Can’t save an Imported Excel sheet to Database in VB 2005

NickJ

Member
Joined
Apr 29, 2005
Messages
21
Programming Experience
Beginner
Hi guys
I have this program that imports and Excel spreadsheet to a database, but when I try and save the imported information, nothing is saved.
Here is my code I have so far….

VB.NET:
   [FONT=&quot] [/FONT]
   [FONT=&quot]    [COLOR=blue]Private[/COLOR] [COLOR=blue]Sub[/COLOR] bindingNavigatorSaveItem_Click([COLOR=blue]ByVal[/COLOR] sender [COLOR=blue]As[/COLOR] System.Object, [COLOR=blue]ByVal[/COLOR] e [COLOR=blue]As[/COLOR] System.EventArgs) [COLOR=blue]Handles[/COLOR] bindingNavigatorSaveItem.Click[/FONT]
   [FONT=&quot]        [COLOR=blue]If[/COLOR] [COLOR=blue]Me[/COLOR].Validate [COLOR=blue]Then[/COLOR][/FONT]
   [FONT=&quot]            [COLOR=blue]Me[/COLOR].StockBindingSource.EndEdit()[/FONT]
   [FONT=&quot]            [COLOR=blue]Me[/COLOR].StockTableAdapter.Update([COLOR=blue]Me[/COLOR].StockDataSet.Stock)[/FONT]
   [FONT=&quot]        [COLOR=blue]Else[/COLOR][/FONT]
   [FONT=&quot]            System.Windows.Forms.MessageBox.Show([COLOR=blue]Me[/COLOR], [COLOR=maroon]"Validation errors occurred."[/COLOR], [COLOR=maroon]"Save"[/COLOR], System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning)[/FONT]
   [FONT=&quot]        [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR][/FONT]
   [FONT=&quot]    [COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR][/FONT]
   [COLOR=blue][FONT=&quot] [/FONT][/COLOR]
   [COLOR=blue][FONT=&quot]Private[/FONT][/COLOR][FONT=&quot] [COLOR=blue]Sub[/COLOR] ImportBtn_Click([COLOR=blue]ByVal[/COLOR] sender [COLOR=blue]As[/COLOR] [COLOR=blue]Object[/COLOR], [COLOR=blue]ByVal[/COLOR] e [COLOR=blue]As[/COLOR] System.EventArgs) [COLOR=blue]Handles[/COLOR] ImportBtn.Click[/FONT]
   [FONT=&quot]        [COLOR=blue]Dim[/COLOR] DS [COLOR=blue]As[/COLOR] System.Data.DataSet[/FONT]
   [FONT=&quot]        [COLOR=blue]Dim[/COLOR] MyAdapter [COLOR=blue]As[/COLOR] System.Data.OleDb.OleDbDataAdapter[/FONT]
   [FONT=&quot]        [COLOR=blue]Dim[/COLOR] MyConnection [COLOR=blue]As[/COLOR] System.Data.OleDb.OleDbConnection[/FONT]
   [FONT=&quot]        MyConnection = [COLOR=blue]New[/COLOR] System.Data.OleDb.OleDbConnection( _[/FONT]
   [FONT=&quot]              [COLOR=maroon]"provider=Microsoft.Jet.OLEDB.4.0; "[/COLOR] & _[/FONT]
   [FONT=&quot]              [COLOR=maroon]"data source=D:\Stock.XLS; "[/COLOR] & _[/FONT]
   [FONT=&quot]              [COLOR=maroon]"Extended Properties=Excel 8.0;"[/COLOR])[COLOR=green][/COLOR][/FONT]
   [FONT=&quot]        MyAdapter = [COLOR=blue]New[/COLOR] System.Data.OleDb.OleDbDataAdapter( _[/FONT]
   [FONT=&quot]              [COLOR=maroon]"select * from [Sheet1$]"[/COLOR], MyConnection)[/FONT]
   [FONT=&quot]        DS = [COLOR=blue]New[/COLOR] System.Data.DataSet()[/FONT]
   [FONT=&quot]        MyAdapter.Fill(DS, [COLOR=maroon]"StockDataGridView"[/COLOR])[/FONT]
   [FONT=&quot]        MyConnection.Close()[/FONT]
   [FONT=&quot]        StockDataGridView.DataSource = DS.Tables([COLOR=maroon]"StockDataGridView"[/COLOR])[/FONT]

[FONT=&quot] [/FONT]
Any ideas why this is not saving?

Thanks guys

Nick
 
Back
Top