problem in updating database [modified]
-
Hi, I am having problem to update the database from the changes made to DGV. Following is the code and line in the bold doesn't update the database. Please help me
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Db1DataSet.Sheet1' table. You can move, or remove it, as needed.
Me.Sheet1TableAdapter.Fill(Me.Db1DataSet.Sheet1)End Sub Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then Dim fi As New FileInfo(OpenFileDialog1.FileName) Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;Data Source=" & fi.DirectoryName Dim objConn As New OleDbConnection(sConnectionString) Dim objDataSet As DataSet = New DataSet() objConn.Open() Dim objCmdSelect As New OleDbCommand("SELECT \* FROM " & fi.Name, objConn) Dim objAdapter1 As New OleDbDataAdapter objAdapter1.SelectCommand = objCmdSelect objAdapter1.Fill(objDataSet, "test") DataGridView1.DataSource = objDataSet.Tables(0).DefaultView objConn.Close() ** Me.Sheet1TableAdapter.Update(Me.Db1DataSet.Sheet1)** End If End Sub
modified on Saturday, April 11, 2009 3:26 AM
-
Hi, I am having problem to update the database from the changes made to DGV. Following is the code and line in the bold doesn't update the database. Please help me
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Db1DataSet.Sheet1' table. You can move, or remove it, as needed.
Me.Sheet1TableAdapter.Fill(Me.Db1DataSet.Sheet1)End Sub Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If OpenFileDialog1.ShowDialog(Me) = DialogResult.OK Then Dim fi As New FileInfo(OpenFileDialog1.FileName) Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Text;Data Source=" & fi.DirectoryName Dim objConn As New OleDbConnection(sConnectionString) Dim objDataSet As DataSet = New DataSet() objConn.Open() Dim objCmdSelect As New OleDbCommand("SELECT \* FROM " & fi.Name, objConn) Dim objAdapter1 As New OleDbDataAdapter objAdapter1.SelectCommand = objCmdSelect objAdapter1.Fill(objDataSet, "test") DataGridView1.DataSource = objDataSet.Tables(0).DefaultView objConn.Close() ** Me.Sheet1TableAdapter.Update(Me.Db1DataSet.Sheet1)** End If End Sub
modified on Saturday, April 11, 2009 3:26 AM
What sort of database, looks like an old DBF connection method. I suspect this has nothing to do with a database but is an attempt to read in excel files!
Never underestimate the power of human stupidity RAH
-
What sort of database, looks like an old DBF connection method. I suspect this has nothing to do with a database but is an attempt to read in excel files!
Never underestimate the power of human stupidity RAH
-
its access database in addition to the csv file. Reading from csv file into DGV and updating an existing access database from that DGV. I hope I made it clear.
Well, I can tell your SQL statement is wrong. Your code says something like this:
SELECT \* FROM C:\\folder\\somefile.mdf
which will not work at all. You're trying to try a file path as a table in SQL. You have to provide a TABLE name in the database to the SQL statement, not a file path. Seriously, you're missing the very basic concepts of working with databases. I highly suggest picking up a book on VB.NET and ADO.NET and working through them.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008