Hi, i'm working on a grid, where the data can be saved, modified and deleted from the grid and effects in the database. I have a problem,i.e after I enter data in one row and goto the next row, the next row automatically gets filled by the same data as in the previous row. Please somebody help me, I have posted the patch below.. Thanks in advance.
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
If (con.State = ConnectionState.Open) Then
con.Close()
End If
con.Open()
Dim v_SelectRow As Integer
v_SelectRow = Me.DataGridView1.CurrentRow.Index
Dim CMD As New SqlCommand("fetch_dtls", con)
CMD.CommandType = CommandType.StoredProcedure
Dim ad As New SqlDataAdapter(CMD)
Dim value1 As String = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()
'CMD.Parameters.Add("@emp_no", value1)
CMD.Parameters.Add("@emp_no", SqlDbType.VarChar).Value = value1
CMD.ExecuteScalar()
Dim dt As New DataTable
CMD.Connection = con
If (con.State = ConnectionState.Open) Then
con.Close()
End If
Me.Refresh()
con.Open()
ad.Fill(dt)
If dt.Rows.Count > 0 Then
txtComboBox1.Text = dt.Rows(0)("Loan_code")
txtdisb_date.Text = dt.Rows(0)("Disb_date")
txtsanc_date.Text = dt.Rows(0)("Sanc_date")
txtno_of_inst.Text = dt.Rows(0)("No_of_inst")
txtsanc_amt.Text = dt.Rows(0)("Sanc_amt")
End If
End Sub
Private Sub DataGridView1_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Open()
'Dim v_SelectRow As Integer
'v_SelectRow = Me.DataGridView1.CurrentRow.Index
Dim value1 As String = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()
Dim CMD As New SqlCommand("select H01_emp_num from H01_identfcatn", con)
Dim ad As New SqlDataAdapter(CMD)
CMD.Parameters.Add("@emp_no", SqlDbType.VarChar).Value = value1
CMD.Parameters("@emp_no").Value = value1
Dim dt As New DataTable
CMD.Connection = con
value1 = Me.DataGridView1.SelectedCells.Item(0).Value.ToString & ""
con.Close()
End Sub
Private Sub DataGridView1_CellEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEnter
If con.State = ConnectionState.Open Then
con.Close()
End If
con.Open()
'Dim v_SelectRow As Integer
'v_SelectRow = Me.DataGridView1.CurrentRow.Index
Dim CMD As New SqlCommand("val_name", con)
CMD.CommandType = CommandType.StoredProcedure
Dim ad As New SqlDataAdapter(CMD)
Dim value1 As String
Me.Refresh()
value1 = DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex).Value.ToString()
CMD.Parameters.Add("@emp_no", SqlDbType.VarChar, 50, value1)
CMD.Parameters("@emp_no").Value = value1
ad.Fill(dt)
CMD.Connection = con
For I As Integer = 0 To dt.Rows.Count - 1
If dt.Rows.Count > 0 Then
'DataGridView1.Rows(I).Cells(I).Value = dt.Rows(0)("H01_First_Name")
DataGridView1.CurrentRow.Cells(1).Value = dt.Rows(0)("H01_First_Name")
DataGridView1.CurrentRow.Cells(2).Value = txtsanc_amt.Text
Me.Refresh()
End If
Next
con.Close()
End Sub