I have already asked DevExpress this question which they have told me I have problem with my code that involves deleting a row from a DevExpress Gridview. Basically, I have a VB code-behind routine:
Protected Sub ASPxGridViewUnscheduledReviews_RowDeleting(ByVal sender As Object, ByVal e As DevExpress.Web.Data.ASPxDataDeletingEventArgs) Handles ASPxGridViewUnscheduledReviews.RowDeleting
'Dim aspxGridView As ASPxGridView = sender
Dim StatusID As Integer = CType(e.Keys("AcrStatusID"), Integer)
'delete row from ACRStatus table where AcrStatusID = StatusID
Try
lblMessage.Text = String.Empty
'Dim bl As New CYCIS_BL.Reviews
CYCIS_DL.Reviews.**UnscheduledReviewDelete(StatusID)**
Response.Redirect("ACR_RemoveUnSchReview.aspx")
Catch ex As Exception
lblMessage.Text = ex.Message
End Try
End Sub
where UnscheduledReviewDelete(StatusID) calls a Public Shared Sub from a Data Layer Reviews.vb class, which in turn executes an SQL stored procedure to delete the selected record.
The subroutine in Reviews is:
Public Shared Sub UnscheduledReviewDelete(ByVal StatusID As Integer)
Using dbManager As New DBManager(DataProviderEnums.SqlServer, SQLConnectionHelper.CONN_STRING)
Try
With dbManager
.Open()
.CreateParameters(1)
.AddParameters(0, "#StatusID", StatusID)
.ExecuteNonQuery(CommandType.StoredProcedure, "UnscheduledReviewDelete")
End With
Catch ex As Exception
Throw
End Try
End Using
End Sub
I have saved and built and rebuilt the class file and solution several times. and yet every time I build the solution the compiler throws this same error and the dynamic metadata of Reviews class shows every routine and function except for the one above. Why is it not recognizing the subroutine as part of the Reviews class?
Related
I have a datagridview bound to a table that seems to work fine, but will not save changes to the database. I am using the same code as I used in another project, which did save changes, so I am flummoxed. Also, I have debugged and the save code is being called, just not working. The code in the form calls a separate class with business logic.
Code in the form below:
Private Sub frmAdminAssign_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' Below is generated by Visual Studio when I select my data source for my datagridview
Credit_adminTableAdapter.Fill(DataSet1.credit_admin) ' Foreign key relationship to table being updated (lookup table).
LoanTableAdapter.Fill(DataSet1.loan) ' Table being updated
admin_assign = New AdminAssign()
admin_assign.FilterUnassigned(dgvAssign, LoanTableAdapter)
End Sub
Private Sub dgvAssign_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgvAssign.CellEndEdit
admin_assign.SaveAssignmentChanges(DataSet1, LoanTableAdapter)
End Sub
Below is code in business logic class called from above:
Public Sub SaveAssignmentChanges(ByRef data_set As DataSet1, ByRef loan_table_adapter As DataSet1TableAdapters.loanTableAdapter)
' Saves changes to DB.
Dim cmdBuilder As SqlCommandBuilder
cmdBuilder = New SqlCommandBuilder(loan_table_adapter.Adapter)
loan_table_adapter.Adapter.UpdateCommand = cmdBuilder.GetUpdateCommand(True)
Try
loan_table_adapter.Adapter.Update(data_set)
Catch unknown_ex As Exception
Dim error_title As String = "Database Save Error"
Dim unknown_error As String = $"There was an error saving to the database.{vbNewLine}Error: {unknown_ex.ToString}"
MessageBox.Show(unknown_error, error_title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
End Sub
The data from the datagridview is not saving to the tableadapter, which I found out by adding the lines below in the start of the second procedure:
Dim x As String = loan_table_adapter.GetData()(0)("note_number") ' Unchanged, check was right row
Dim y As String = loan_table_adapter.GetData()(0)("credit_admin_id") ' Changed in datagridview but still null (get null error)
I figured it out, it was related to a filter routine that is not above where I passed a tableadapter byref when I should have passed a datatable byval. So, related to one of jmcilhinney's byref vs byval comments above. See problem code below:
Public Sub FilterUnassigned(ByRef dgv_assigned As DataGridView, loan_table_adapter As DataSet1TableAdapters.loanTableAdapter)
' Should have passed in DataSet1.loan DataTable ByVal and used it below:
Dim unassigned_loans As DataView = loan_table_adapter.GetData().DefaultView()
unassigned_loans.RowFilter = "request_date Is Not Null AND numerated_assigned_user Is Null"
dgv_assigned.DataSource = unassigned_loans
End Sub
Also, skipping the SQLCommandBuilder commands and my code still works. So, all I need is one line as per jmcilhinney instead of 4 (excl error handling) as per below:
Try
loan_table_adapter.Update(data_set)
Catch unknown_ex As Exception
Dim error_title As String = "Database Save Error"
Dim unknown_error As String = $"There was an error saving to the database. Please contact Kevin Strickler to resolve.{vbNewLine}Error: {unknown_ex.ToString}"
MessageBox.Show(unknown_error, error_title, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
I have a WinForm that I want to pass a variable to. This form may or may not already be open. The code I was using would check to see if the form was open (using an IsOpen function) and then do a .BringToFront if it was open, or it would do a .Show if it was not open.
Now with trying to use New() to pass the variable, things are not working as expected. Creating the form variable, using Dim AdBook As New frmAddressBook, means a new instance of the form is created. When I run the IsOpen function, it does see the form. However, since I created a "new" form, when I run the AdBook.FillPatientInfo function of that form, the other variables have not been set up because that "new" form has not actually been loaded.
The only solution I have found thus far is to close the form and then open it again. But that sounds like more overhead than it should be. And besides, I'm not sure how I would close a form that I can't get a hold of.
Form 1 Click Event:
Private Sub tsmiAddressBook_Click(sender As Object, e As EventArgs) Handles tsmiAddressBook.Click
If IsDBNull(dgvPhysician.CurrentRow.Cells(1).Value) Then Exit Sub
Dim AdBook As New frmAddressBook(CInt(dgvPhysician.CurrentRow.Cells(1).Value))
If IsOpen(AdBook, Reflection.MethodBase.GetCurrentMethod().Name) Then
AdBook.BringToFront()
AdBook.FillPatientInfo(CInt(dgvPhysician.CurrentRow.Cells(1).Value))
Else
AdBook.Show(Me)
End If
End Sub
Form 2 New() code:
Private intID As Integer = Nothing
Public Sub New(ByVal newID As Integer)
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
intID = newID
End Sub
Code that checks to see if form IsOpen:
Public Function IsOpen(ByVal frm As Form, SubName As String) As Boolean
Try
Dim frmCol As New FormCollection()
frmCol = Application.OpenForms
Dim Cnt As Integer = 0
For Each f As Form In frmCol
If f.Name = frm.Name Then Cnt += 1
Next
Return CBool(IIf(Cnt > 0, True, False))
Catch ex As Exception
CustExErrorMsg("Functions", Reflection.MethodBase.GetCurrentMethod().Name, ex.Message)
Return False
End Try
End Function
I'm trying to connect to my database and I'm getting this error message (ex):
I've another function which opens DB and load some data, it works fine without any error... But when I try to use this, it returns me this error, the line 175 is "cn.Open()".
My connection string and Local_DB is both same as other functions which are working without errors.
Private Sub AtualizaClientes(ID As Integer)
' Local da DataBase
Dim Local_DB As String
Local_DB = "C:\Users\Heitor BASAM\Desktop\Sistema\DataBase_Sistema.accdb"
Try
Dim cn As New OleDb.OleDbConnection
cn.ConnectionString = $"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={Local_DB}"
cn.Open()
cn.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Glad you fixes your problem! Just a few bits to tidy up the code.
Always use Using...End Using with database objects that expose a Dispose method. They may be using unmanaged objects and their dispose methods must run to release these resources. The End Using takes care of this for you even if there is an error.
You can let the error bubble up to the calling code, user interface code. Wrap the call to AtualizaClientes in a Try...Catch...End Try
Private Sub AtualizaClientes(ID As Integer)
Dim Local_DB = "C:\Users\Heitor BASAM\Desktop\Sistema\DataBase_Sistema.accdb"
Using cn As New OleDb.OleDbConnection($"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={Local_DB}")
cn.Open()
End Using
End Sub
EDIT
You would add the Try...End Try to the UI code. Example...
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim id As Integer = 7
Try
AtualizaClientes(id)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
I figured out the problem! I've a function when a especify textbox is changed, it calls this "AtualizaClientes" function. The problem is, when you load the form, it runs a "TextChanged" event in every textbox and trys to run the database before loading it. This was causing the error message.
To solve this problem, I made a boolean variable which returns true after loading the database. So, I changed my textchanged event to run only if this variable is true.
I am building a small app that is pulling script from within an object. I'm down to the portion where my code is pulling back the field from the object that has the script and I'm getting this error.
"reference to a non-shared member requires an object reference"
I'm not sure what to change or how to get around this. Does anyone out there have any suggestions?
Here is the code that i have so far. It's a simple app that has a combobox that you choose the company from and on button click it will get the script and show it in the textbox.
Here is my code:
Imports System.IO
Public Class Form1
Public M3System As MILLSYSTEMLib.System
Public M3Script As MILLCOMPANYLib.CScripting
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'On Error Resume Next
Try
Dim Approved As Integer
' Create a Millennium system obects
M3System = CreateObject("MillSystem.System")
M3System.Load("Millennium")
'run login script
Dim User As Object = M3System.Login()
' See if login worked
If User Is Nothing Then
'MsgBox("Login failed!")
Approved = 0
Else
'MsgBox("Login successful")
'if approved=1 then the user is able to access M3
Approved = 1
End If
'populate combo box
For Each Company In M3System.Companies
cb_COID.Items.Add(Company.Field("co").ToString)
Next
Catch ex As Exception
Me.Close()
End Try
End Sub
Public Sub btn_LoadScript_Click(sender As Object, e As EventArgs) Handles btn_LoadScript.Click
Dim CoCode As String = cb_COID.SelectedItem
Dim script As String = M3Script.vbscript
If IsNothing(cb_COID) Then
MessageBox.Show("Select a Company Code")
End If
For Each CoCode In M3Script.co
tb_Script.Text = script
Next
End Sub
I'm guessing that the line you are failing on is Dim script As String = M3Script.vbscript
If that is the case, it's because you are declaring the M3Script, but you are not creating an instance of it.
Try setting the object somewhere by adding M3Script = new MILLCOMPANYLib.CScripting to your code, or however you would load it (perhaps M3Script = CreateObject("MillSystem.Script")?)
My specific question is: How to ignore windows events when in a child form called from that event handler?
Some context: My application captures a fingerprint, and puts up the next form (secondForm) when a print is recognized against the database. I want to ignore any prints they put in while their secondForm is up. The trouble is that when people press the print multiple times, or while their secondForm is up, then the events are queued until after the secondForm closes, so I get multiple calls to the event handler for that person.. I've tried so many ways around this, including calling the routine that open secondForm as a delegate(is that even appropriate), putting a global boolean in the event handler, etc. If I disable fingerprint capture during the oncomplete eventhandler, my form never shows up.
Am I missing something obvious to you here? Much gratitude for any ideas...
Imports DPFP.Capture ' DigitalPersona fingerprint reader library
' Simple example to capture a fingerprint from DigitalPersona fingerprint reader.
Public Class SimpleFP
Implements DPFP.Capture.EventHandler
Private mIgnore As Boolean
Public eventHandlerComplete As DPFP.Capture.EventHandler
Public WithEvents mCapture As DPFP.Capture.Capture
Private Sub WaitForFPrint_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
' set up finger print capture
mCapture = New DPFP.Capture.Capture
mCapture.EventHandler = Me
mCapture.StartCapture()
Catch ex As Exception
MsgBox("Problem starting fingerprint reader: " & ex.Message)
End Try
End Sub
Public Sub FPOnComplete(ByVal Capture As Object, ByVal sernum As String, ByVal sample As DPFP.Sample) _
Implements DPFP.Capture.EventHandler.OnComplete
'mCapture.StopCapture()
'This is what I want to do, but when I leave this in, my secondForm won't stay up
Dim s As String = displaySecondScreen(sample)
showStatus(s)
'mCapture.StartCapture()
'This is what I want to do, but when I leave this in, my secondForm won't stay up
End Sub
' Put up second form. This is called from the fingerprint OnComplete event handler.
Private Function displaySecondScreen(ByVal sample As DPFP.Sample) As String
Dim status As String = "OK"
Try
Dim x As DPFP.FeatureSet
x = extractFeatures(sample)
' This is where I match the fp in my code, but I removed here to simplify
If True Then
Dim frm As New frmSecondForm
frm.ShowDialog(Me)
frm.Dispose()
Else
' No fingerprint match - normal case
status = "Fingerprint not recognized"
End If
Catch ex As Exception
status = "Exception during fingerprint verification: " & ex.Message
End Try
Return status
End Function
' Made rudimentary for this example, but I thought some person new to dpfp may be able to use this
Private Function extractFeatures(ByVal sample As DPFP.Sample) As DPFP.FeatureSet
Dim extractor As New DPFP.Processing.FeatureExtraction()
Dim feedback As New DPFP.Capture.CaptureFeedback()
Dim features As New DPFP.FeatureSet()
extractor.CreateFeatureSet(sample, DPFP.Processing.DataPurpose.Verification, feedback, features)
If feedback = DPFP.Capture.CaptureFeedback.Good Then
End If
Return features
End Function
Private Sub debugOut(ByVal s As String)
Console.WriteLine(s)
End Sub
' Display status on first form
Delegate Sub showStatusCallback(ByVal s As String)
Private Sub showStatus(ByVal s As String)
If lblStatus.InvokeRequired Then
Dim d As New showStatusCallback(AddressOf showStatus)
Me.Invoke(d, New Object() {s})
Else
lblStatus.Text = s
End If
End Sub
' ... followed by other implements dpfp eventhandlers not in use....
' ....
End Class