Evening
when i am leaving a cell in a datagrid view i want add a record to a sqldatabase through a stored procedure. i am having a lot of troub;e with this and really is starting to do my head in.
here is the subprocedure for the stored procedure which is working fine
Private Sub AddVehicle()
'objdata = New SQLDatabase
Dim intindex As Integer
Try
objdata.InitializeReader("AddVehicleType")
objdata.AddParameter("@VehicleType", SqlDbType.VarChar, 50, objDataDs.Tables("Customers").Rows(intindex).Item("VehicleType"))
objdata.CloseConnection()
objdata.ExecuteReader()
'objdata.CloseReader()
Catch SqlErr As SqlException
MessageBox.Show(SqlErr.Message)
End Try
End Sub
also here is the sub leave for datagridveiw
Private Sub dgCustomers_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgCustomers.CellLeave
Dim dr As DataRow
Dim intIndex As Integer
If Not IsNothing(objdata) Then
For intIndex = objDataDs.Tables("Customers").Rows.Count - 1 To 0 Step -1
If e.ColumnIndex = 1 Then
If objDataDs.Tables("Customers").Rows(intIndex).RowState = DataRowState.Added Then
AddVehicle()
End If
End If
objDataDs.Tables("Customers").Rows(intIndex).AcceptChanges()
dr = objDataDs.Tables("Customers").NewRow()
objDataDs.Tables("Customers").Rows.Add(dr)
Next
End If
End Sub
the procedure is adding in 4 new rows when i leave the data field
can any 1 help
cheers
Mac
when i am leaving a cell in a datagrid view i want add a record to a sqldatabase through a stored procedure. i am having a lot of troub;e with this and really is starting to do my head in.
here is the subprocedure for the stored procedure which is working fine
Private Sub AddVehicle()
'objdata = New SQLDatabase
Dim intindex As Integer
Try
objdata.InitializeReader("AddVehicleType")
objdata.AddParameter("@VehicleType", SqlDbType.VarChar, 50, objDataDs.Tables("Customers").Rows(intindex).Item("VehicleType"))
objdata.CloseConnection()
objdata.ExecuteReader()
'objdata.CloseReader()
Catch SqlErr As SqlException
MessageBox.Show(SqlErr.Message)
End Try
End Sub
also here is the sub leave for datagridveiw
Private Sub dgCustomers_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgCustomers.CellLeave
Dim dr As DataRow
Dim intIndex As Integer
If Not IsNothing(objdata) Then
For intIndex = objDataDs.Tables("Customers").Rows.Count - 1 To 0 Step -1
If e.ColumnIndex = 1 Then
If objDataDs.Tables("Customers").Rows(intIndex).RowState = DataRowState.Added Then
AddVehicle()
End If
End If
objDataDs.Tables("Customers").Rows(intIndex).AcceptChanges()
dr = objDataDs.Tables("Customers").NewRow()
objDataDs.Tables("Customers").Rows.Add(dr)
Next
End If
End Sub
the procedure is adding in 4 new rows when i leave the data field
can any 1 help
cheers
Mac