Hi,
my app connects to a VisualFoxpro database (using oledb provider).
There are about 150 tables in this database.
I list the tables in a listbox.
The user can select a table and the content is displayed in a datagridview.
I can also connect to various databases (local machine or network).
So the connectionstring, listbox and datagridview are all more or less dynamic.
Now I want to update a cell in the grid (and from there update the table in the dataset), but I don't want to write code for 150 tableadapters.
I've done this for 1 table and all works fine.
Here is the code:
The question is: how do I set updRow to be an updaterow of the selected table without writing code for 150 tables.
As far as I know, I need an updaterow with te oledbdataadapter (without it there is no update in the database).
Or is there another way to do this.
Until now reading the posts on this forum helped me to find what i need.
Can't find anything on this.
Appreciate your help.
my app connects to a VisualFoxpro database (using oledb provider).
There are about 150 tables in this database.
I list the tables in a listbox.
The user can select a table and the content is displayed in a datagridview.
I can also connect to various databases (local machine or network).
So the connectionstring, listbox and datagridview are all more or less dynamic.
Now I want to update a cell in the grid (and from there update the table in the dataset), but I don't want to write code for 150 tableadapters.
I've done this for 1 table and all works fine.
Here is the code:
VB.NET:
Dim FPconn As OleDb.OleDbConnection
Dim FPadap As OleDb.OleDbDataAdapter
Dim cmd As OleDb.OleDbCommand
[B]Dim updRow As <dataset>.<table>Row[/B]
Dim kol, rij, antw As Integer
Dim strOud, strNew, strUn, strDbTable_SQL As String
kol = DGinh.CurrentCell.ColumnIndex
strUn = DGinh.CurrentRow.Cells("unid").Value
strOud = DGinh.CurrentCell.Value
strNew = InputBox("Wijzig de waarde in", "Wijzigen", strOud)
DGinh.CurrentCell.Value = strNew
DGinh.Update()
FPconn = New OleDb.OleDbConnection(My.Settings.<conn.strin>)
Me.<dataset>.Tables(strTabelnaam).Rows.Clear()
strDbTable_SQL = "SELECT * FROM " & ListBox1.SelectedItem
FPadap = New OleDb.OleDbDataAdapter(strDbTable_SQL, FPconn)
FPadap.Fill(Me.<dataset>.Tables(strTabelnaam))
For rij = 0 To Me.<dataset>.Tables(strTabelnaam).Rows.Count - 1
If Me.<dataset>.Tables(strTabelnaam).Rows(rij).Item(0) = strUn Then
Exit For
End If
Next
updRow = Me.<dataset>.Tables(strTabelnaam).Rows(rij)
ZetCurrCell(kol, strUn)
antw = MsgBox(strOud & " wijzigen in " & strNew & "?", MsgBoxStyle.YesNo)
cmd = New OleDb.OleDbCommand
If antw = MsgBoxResult.Yes Then
updRow.Item(DGinh.CurrentCell.ColumnIndex) = strNew
cmd.CommandText = "UPDATE '" & strTabelnaam & _
"' SET " & DGinh.Columns(kol).HeaderText & " = '" & strNew & "' WHERE unid = '" & strUn & "'"
cmd.Connection = FPconn
FPadap.UpdateCommand = cmd
Me.Validate()
Me.<bindingsource>.EndEdit()
Try
FPadap.Update(Me.<dataset>.Tables(strTabelnaam))
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
FPconn.Close()
As far as I know, I need an updaterow with te oledbdataadapter (without it there is no update in the database).
Or is there another way to do this.
Until now reading the posts on this forum helped me to find what i need.
Can't find anything on this.
Appreciate your help.
Last edited by a moderator: