H
Horst Mayer
Hello everybody,
I update the data so:
dtData1 = GetDataTable(OpenConnection, "select * from nursing where
PatientID = 33 order by ID", objAdapter)
Dim cmdBuilder As New SqlClient.SqlCommandBuilder(objAdapter)
objAdapter.UpdateCommand = cmdBuilder.GetUpdateCommand
With dtData1
.Rows(DataGridView1.CurrentRow.Index).Item("PatientId") =
iPatientID
.Rows(DataGridView1.CurrentRow.Index).Item("Diagnose") = "New
diagnosis"
.Rows(DataGridView1.CurrentRow.Index).Item("Erstellt") = sUserID
End With
objAdapter.Update(dtData1)
dtData1 = GetDataTable(OpenConnection, "select * from nursing where
PatientID = 33 order by ID")
DataGridView1.DataSource = dtData1
Now all controlls (Grid, Textboxes) show to the first record. How to bring
datatable dtData1 to go to the last modified record?
Here is the complete code in the module:
Public Class aaa
Dim dtData1 As New DataTable
Dim iPatientID As Integer
Dim objAdapter As New SqlClient.SqlDataAdapter
Private Sub frmHandlung_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
dtData1 = GetDataTable(OpenConnection, "select * from nursing where
PatientID = 33", objAdapter)
Me.DataGridView1.DataSource = dtData1
iPatientID = 33
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
dtData1 = GetDataTable(OpenConnection, "select * from nursing where
PatientID = 33 order by ID", objAdapter)
Dim cmdBuilder As New SqlClient.SqlCommandBuilder(objAdapter)
objAdapter.UpdateCommand = cmdBuilder.GetUpdateCommand
With dtData1
.Rows(DataGridView1.CurrentRow.Index).Item("PatientId") =
iPatientID
.Rows(DataGridView1.CurrentRow.Index).Item("Diagnose") = "New
diagnosis"
.Rows(DataGridView1.CurrentRow.Index).Item("Erstellt") = sUserID
End With
objAdapter.Update(dtData1)
dtData1 = GetDataTable(OpenConnection, "select * from nursing where
PatientID = 33 order by ID")
DataGridView1.DataSource = dtData1
End Sub
Private Function GetDataTable(ByRef objConn As SqlClient.SqlConnection,
ByVal SQLQuery As String, Optional ByRef dataAdapter As
SqlClient.SqlDataAdapter = Nothing) As DataTable
Dim ds As New DataSet, objAdapter As SqlClient.SqlDataAdapter,
objcmd As SqlClient.SqlCommand
If objConn.State = ConnectionState.Open Then
objcmd = New SqlClient.SqlCommand(SQLQuery, objConn)
objAdapter = New SqlClient.SqlDataAdapter()
objAdapter.SelectCommand = objcmd
If Not dataAdapter Is Nothing Then
dataAdapter = objAdapter
End If
objAdapter.Fill(ds)
objConn.Close()
Return ds.Tables(0)
Else
Return Nothing
End If
End Function
End Class
Thank you very much for your ideas!
Horst
I update the data so:
dtData1 = GetDataTable(OpenConnection, "select * from nursing where
PatientID = 33 order by ID", objAdapter)
Dim cmdBuilder As New SqlClient.SqlCommandBuilder(objAdapter)
objAdapter.UpdateCommand = cmdBuilder.GetUpdateCommand
With dtData1
.Rows(DataGridView1.CurrentRow.Index).Item("PatientId") =
iPatientID
.Rows(DataGridView1.CurrentRow.Index).Item("Diagnose") = "New
diagnosis"
.Rows(DataGridView1.CurrentRow.Index).Item("Erstellt") = sUserID
End With
objAdapter.Update(dtData1)
dtData1 = GetDataTable(OpenConnection, "select * from nursing where
PatientID = 33 order by ID")
DataGridView1.DataSource = dtData1
Now all controlls (Grid, Textboxes) show to the first record. How to bring
datatable dtData1 to go to the last modified record?
Here is the complete code in the module:
Public Class aaa
Dim dtData1 As New DataTable
Dim iPatientID As Integer
Dim objAdapter As New SqlClient.SqlDataAdapter
Private Sub frmHandlung_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
dtData1 = GetDataTable(OpenConnection, "select * from nursing where
PatientID = 33", objAdapter)
Me.DataGridView1.DataSource = dtData1
iPatientID = 33
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
dtData1 = GetDataTable(OpenConnection, "select * from nursing where
PatientID = 33 order by ID", objAdapter)
Dim cmdBuilder As New SqlClient.SqlCommandBuilder(objAdapter)
objAdapter.UpdateCommand = cmdBuilder.GetUpdateCommand
With dtData1
.Rows(DataGridView1.CurrentRow.Index).Item("PatientId") =
iPatientID
.Rows(DataGridView1.CurrentRow.Index).Item("Diagnose") = "New
diagnosis"
.Rows(DataGridView1.CurrentRow.Index).Item("Erstellt") = sUserID
End With
objAdapter.Update(dtData1)
dtData1 = GetDataTable(OpenConnection, "select * from nursing where
PatientID = 33 order by ID")
DataGridView1.DataSource = dtData1
End Sub
Private Function GetDataTable(ByRef objConn As SqlClient.SqlConnection,
ByVal SQLQuery As String, Optional ByRef dataAdapter As
SqlClient.SqlDataAdapter = Nothing) As DataTable
Dim ds As New DataSet, objAdapter As SqlClient.SqlDataAdapter,
objcmd As SqlClient.SqlCommand
If objConn.State = ConnectionState.Open Then
objcmd = New SqlClient.SqlCommand(SQLQuery, objConn)
objAdapter = New SqlClient.SqlDataAdapter()
objAdapter.SelectCommand = objcmd
If Not dataAdapter Is Nothing Then
dataAdapter = objAdapter
End If
objAdapter.Fill(ds)
objConn.Close()
Return ds.Tables(0)
Else
Return Nothing
End If
End Function
End Class
Thank you very much for your ideas!
Horst