i am inserting data using datagrid but my problem is that it is not inserting the last row item itemqty value only,in one row i am inserting groupcode,itemcode,itemqty,entrydate,locationcode,addt only .the itemqty of last row is not inserted if i give itemqty=1 by default it takes 0 and all(groupcode,itemcode,entrydate,locationcode,addt) remaining item is inserted correctely.like that if i insert 2 row row 1 is correctely inserted but row 2 itemqty is 0,but when i insert 2 row with clicking outside the itemqty cell after putting the value in itemqty cell then it insert the correct value in database.there is some focus or click event problem plz help me ........ code is given below
Sub modify_inventory(ByVal frm As frminventory)
Dim writesqltime As String
Dim writesqldate As String
writesqldate = Format(CDate(sqldate), "MM/dd/yyyy")
writesqltime = sqltime
Dim cmd = New SqlClient.SqlCommand
If active_frm.Name <> "frminventory" Then
Exit Sub
Else
writesqldate = Format(CDate(sqldate), "MM/dd/yyyy")
Dim j As Integer
con = connect()
con.Open()
For j = 0 To 5
For i = 0 To frm.dgvitem(j).RowCount - 1
If frm.dgvitem(j).Item(4, i).Value <> 0 Then
cmd = New SqlClient.SqlCommand("INSERT INTO minventory(groupcode,itemcode,itemqty,entrydate,locationcode,addt) VALUES('" & frm.dgvitem(j).Item(0, i).Value & "','" & frm.dgvitem(j).Item(1, i).Value & "'," & frm.dgvitem(j).Item(4, i).Value & ",'" & writesqldate & "'," & location_code & ",'" & writesqltime & "' )", con)
cmd.ExecuteNonQuery()
End If
Next i
Next j
con.Close()
If active_frm.Name <> "MDIPOS" Then
active_frm.Close()
End If
MDIpos.Panel1.Visible = False
MDIpos.mnumaster.Enabled = True
MDIpos.MenuItem1.Enabled = True
MDIpos.mnureport.Enabled = True
MDIpos.mnuexit.Enabled = True
MDIpos.mnumodify.Visible = False
MDIpos.mnumodify.Enabled = False
MDIpos.mnuadd.Visible = False
MDIpos.mnuadd.Enabled = False
MDIpos.Mnuclear.Visible = False
MDIpos.Mnuclear.Enabled = False
MDIpos.Mnudelete.Visible = False
MDIpos.Mnudelete.Enabled = False
End If
End Sub