Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

leaving cell in datagrid view

Status
Not open for further replies.

allanmc10

Programmer
Feb 23, 2006
39
GB
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
 
You seem to ask a lot of questions, yet more often than not you don't thank those who help you and have yet to award anyone a star.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top