اول کد زیر تا وقتی اطلاعاتت تو سلول درج شد وارد تکست بشه
Private Sub DataGridView1_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellEndEdit
Try
txt_data.Text = DataGridView1.CurrentRow.Cells(0).Value
txtid_chek.Text = DataGridView1.CurrentRow.Cells(3).Value
txtid_hesab.Text = DataGridView1.CurrentRow.Cells(4).Value
txtmablagh.Text = DataGridView1.CurrentRow.Cells(6).Value
Catch
End Try
بعد هم کد زیر تا وقتی سطر جاری رد شد اطلاعات تکست تو بانک ذخیره بشه البته میشه به جای تکسا هم مستقیم خود سلول رو درج کنی اما من با تکس راحتترم
Private Sub DataGridView1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DataGridView1.KeyDown
If e.KeyCode = Keys.Enter Then
Try
+ ")"InsertCommand.CommandText = "insert into chek(data_sodor,id_chek,id_hesab,mablagh) values('" + txt_data.Text + "' ,'" + txtid_chek.Text + "','" + txtid_hesab.Text + "'," + txtmablagh.Text
ad.InsertCommand.Connection.Open()
ad.InsertCommand.ExecuteNonQuery()
ad.InsertCommand.Connection.Close()
Catch
End Try
MsgBox("اطلاعات ذخیره شد.", MsgBoxStyle.OkOnly + MsgBoxStyle.Information + 0, "ذخیره ی اطلاعات")
DataGridView1.AllowUserToAddRows = True
end if
End Sub