473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DataReader in Excel (Better Post than the last)

I have an Excel Spreadsheet I want to import the records (5 fields) into an
access 2000 DB. Went on the net looking and found stuff for SQL (which I
don't know a thing about) and now I'm confused. (Using VB.NET 2k3) Any help
would be appreciated.

Here is the code I have.... It doesn't work cause it errors out after the
bold comment line.

Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim myDataReader As System.Data.OleDb.OleDbDataReader
Dim ExcelCommand As System.Data.OleDb.OleDbCommand

MyConnection = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=C:\Program Files\97CS\SelfInspect\CheckList\NewCheckList.XLS; "
& _
"Extended Properties=Excel 8.0;")

Dim myTable As System.Data.DataTable
'Object reference not set to an instance of an object.
myDataReader = ExcelCommand.ExecuteReader
Dim myRow As DataRow = myTable.NewRow

While myDataReader.Read
myRow.Item("dbmFilterList") = myDataReader.GetData(0)
myRow.Item("dbmCheckList") = myDataReader.GetData(1)
myRow.Item("dbmNumber") = myDataReader.GetData(2)
myRow.Item("dbmQuestion") = myDataReader.GetData(3)
myRow.Item("dbmReference") = myDataReader.GetData(4)
ODAAddItems.Update(DsAddItems)
EndWhile
Nov 21 '05 #1
3 3937
See some comments with *** in front... you have a lot of problems, I just
pointed out the obvious ones I saw.

***Don't think you need the DataAdapter (since you are using DataReader)
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter

Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim myDataReader As System.Data.OleDb.OleDbDataReader

*** Dim ExcelCommand As NEW System.Data.OleDb.OleDbCommand
Dim ExcelCommand As System.Data.OleDb.OleDbCommand

MyConnection = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=C:\Program Files\97CS\SelfInspect\CheckList\NewCheckList.XLS;
" & _
"Extended Properties=Excel 8.0;")

***Unused line
Dim myTable As System.Data.DataTable
'Object reference not set to an instance of an object.

***This is because you didn't instanticate the ExcelCommand Object
***You will also probably have to tell it way you want data you want the
command to get
***You will need to attach the connection object to the Command, and open
the Connection object
myDataReader = ExcelCommand.ExecuteReader

***This line will give the same error as above, since table isn't
instanciated
***Doesn't look like you use it anyways
Dim myRow As DataRow = myTable.NewRow

While myDataReader.Read
myRow.Item("dbmFilterList") = myDataReader.GetData(0)
myRow.Item("dbmCheckList") = myDataReader.GetData(1)
myRow.Item("dbmNumber") = myDataReader.GetData(2)
myRow.Item("dbmQuestion") = myDataReader.GetData(3)
myRow.Item("dbmReference") = myDataReader.GetData(4)
ODAAddItems.Update(DsAddItems)
EndWhile
"brix_zx2" <br*****@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...
I have an Excel Spreadsheet I want to import the records (5 fields) into an
access 2000 DB. Went on the net looking and found stuff for SQL (which I
don't know a thing about) and now I'm confused. (Using VB.NET 2k3) Any
help
would be appreciated.

Here is the code I have.... It doesn't work cause it errors out after the
bold comment line.

Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim myDataReader As System.Data.OleDb.OleDbDataReader
Dim ExcelCommand As System.Data.OleDb.OleDbCommand

MyConnection = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=C:\Program Files\97CS\SelfInspect\CheckList\NewCheckList.XLS;
"
& _
"Extended Properties=Excel 8.0;")

Dim myTable As System.Data.DataTable
'Object reference not set to an instance of an object.
myDataReader = ExcelCommand.ExecuteReader
Dim myRow As DataRow = myTable.NewRow

While myDataReader.Read
myRow.Item("dbmFilterList") = myDataReader.GetData(0)
myRow.Item("dbmCheckList") = myDataReader.GetData(1)
myRow.Item("dbmNumber") = myDataReader.GetData(2)
myRow.Item("dbmQuestion") = myDataReader.GetData(3)
myRow.Item("dbmReference") = myDataReader.GetData(4)
ODAAddItems.Update(DsAddItems)
EndWhile

Nov 21 '05 #2
Yea, I noticed half of those after I did this post but the other half worked
good, now I'm stuck with the following:

While myDataReader.Read
****Error: Column 'dbmFilterList' does not belong to table****
myRow.Item("dbmFilterList") = myDataReader.GetData(0)
myRow.Item("dbmCheckList") = myDataReader.GetData(1)
myRow.Item("dbmNumber") = myDataReader.GetData(2)
myRow.Item("dbmQuestion") = myDataReader.GetData(3)
myRow.Item("dbmReference") = myDataReader.GetData(4)
ODAAddItems.Update(DsAddItems)
EndWhile

Is this saying that it can't find that in my access database? which is
loaded into a seperate dataset.
"Chris" wrote:
See some comments with *** in front... you have a lot of problems, I just
pointed out the obvious ones I saw.

***Don't think you need the DataAdapter (since you are using DataReader)
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter

Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim myDataReader As System.Data.OleDb.OleDbDataReader

*** Dim ExcelCommand As NEW System.Data.OleDb.OleDbCommand
Dim ExcelCommand As System.Data.OleDb.OleDbCommand

MyConnection = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=C:\Program Files\97CS\SelfInspect\CheckList\NewCheckList.XLS;
" & _
"Extended Properties=Excel 8.0;")

***Unused line
Dim myTable As System.Data.DataTable
'Object reference not set to an instance of an object.

***This is because you didn't instanticate the ExcelCommand Object
***You will also probably have to tell it way you want data you want the
command to get
***You will need to attach the connection object to the Command, and open
the Connection object
myDataReader = ExcelCommand.ExecuteReader

***This line will give the same error as above, since table isn't
instanciated
***Doesn't look like you use it anyways
Dim myRow As DataRow = myTable.NewRow

While myDataReader.Read
myRow.Item("dbmFilterList") = myDataReader.GetData(0)
myRow.Item("dbmCheckList") = myDataReader.GetData(1)
myRow.Item("dbmNumber") = myDataReader.GetData(2)
myRow.Item("dbmQuestion") = myDataReader.GetData(3)
myRow.Item("dbmReference") = myDataReader.GetData(4)
ODAAddItems.Update(DsAddItems)
EndWhile
"brix_zx2" <br*****@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...
I have an Excel Spreadsheet I want to import the records (5 fields) into an
access 2000 DB. Went on the net looking and found stuff for SQL (which I
don't know a thing about) and now I'm confused. (Using VB.NET 2k3) Any
help
would be appreciated.

Here is the code I have.... It doesn't work cause it errors out after the
bold comment line.

Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim myDataReader As System.Data.OleDb.OleDbDataReader
Dim ExcelCommand As System.Data.OleDb.OleDbCommand

MyConnection = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=C:\Program Files\97CS\SelfInspect\CheckList\NewCheckList.XLS;
"
& _
"Extended Properties=Excel 8.0;")

Dim myTable As System.Data.DataTable
'Object reference not set to an instance of an object.
myDataReader = ExcelCommand.ExecuteReader
Dim myRow As DataRow = myTable.NewRow

While myDataReader.Read
myRow.Item("dbmFilterList") = myDataReader.GetData(0)
myRow.Item("dbmCheckList") = myDataReader.GetData(1)
myRow.Item("dbmNumber") = myDataReader.GetData(2)
myRow.Item("dbmQuestion") = myDataReader.GetData(3)
myRow.Item("dbmReference") = myDataReader.GetData(4)
ODAAddItems.Update(DsAddItems)
EndWhile


Nov 21 '05 #3
Unless you changed your program since you last posted this is how you are
creating myRow. You see by this that myTable has no structure.

Dim myTable As New System.Data.DataTable
Dim myRow As DataRow = myTable.NewRow

Try this:

Dim myTable As New System.Data.DataTable
myTable.Columns.Add("dbmFilterList")
.....
myTable.Columns.Add("dbmReference")
Dim myRow As DataRow = myTable.NewRow

Chris

"brix_zx2" <br*****@discussions.microsoft.com> wrote in message
news:B4**********************************@microsof t.com...
Yea, I noticed half of those after I did this post but the other half
worked
good, now I'm stuck with the following:

While myDataReader.Read
****Error: Column 'dbmFilterList' does not belong to table****
myRow.Item("dbmFilterList") = myDataReader.GetData(0)
myRow.Item("dbmCheckList") = myDataReader.GetData(1)
myRow.Item("dbmNumber") = myDataReader.GetData(2)
myRow.Item("dbmQuestion") = myDataReader.GetData(3)
myRow.Item("dbmReference") = myDataReader.GetData(4)
ODAAddItems.Update(DsAddItems)
EndWhile

Is this saying that it can't find that in my access database? which is
loaded into a seperate dataset.
"Chris" wrote:
See some comments with *** in front... you have a lot of problems, I just
pointed out the obvious ones I saw.

***Don't think you need the DataAdapter (since you are using DataReader)
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter

Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim myDataReader As System.Data.OleDb.OleDbDataReader

*** Dim ExcelCommand As NEW System.Data.OleDb.OleDbCommand
Dim ExcelCommand As System.Data.OleDb.OleDbCommand

MyConnection = New System.Data.OleDb.OleDbConnection( _
"provider=Microsoft.Jet.OLEDB.4.0; " & _
"data source=C:\Program
Files\97CS\SelfInspect\CheckList\NewCheckList.XLS;
" & _
"Extended Properties=Excel 8.0;")

***Unused line
Dim myTable As System.Data.DataTable
'Object reference not set to an instance of an object.

***This is because you didn't instanticate the ExcelCommand Object
***You will also probably have to tell it way you want data you want the
command to get
***You will need to attach the connection object to the Command, and open
the Connection object
myDataReader = ExcelCommand.ExecuteReader

***This line will give the same error as above, since table isn't
instanciated
***Doesn't look like you use it anyways
Dim myRow As DataRow = myTable.NewRow

While myDataReader.Read
myRow.Item("dbmFilterList") = myDataReader.GetData(0)
myRow.Item("dbmCheckList") = myDataReader.GetData(1)
myRow.Item("dbmNumber") = myDataReader.GetData(2)
myRow.Item("dbmQuestion") = myDataReader.GetData(3)
myRow.Item("dbmReference") = myDataReader.GetData(4)
ODAAddItems.Update(DsAddItems)
EndWhile
"brix_zx2" <br*****@discussions.microsoft.com> wrote in message
news:96**********************************@microsof t.com...
>I have an Excel Spreadsheet I want to import the records (5 fields) into
>an
> access 2000 DB. Went on the net looking and found stuff for SQL (which
> I
> don't know a thing about) and now I'm confused. (Using VB.NET 2k3) Any
> help
> would be appreciated.
>
> Here is the code I have.... It doesn't work cause it errors out after
> the
> bold comment line.
>
> Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
> Dim MyConnection As System.Data.OleDb.OleDbConnection
> Dim myDataReader As System.Data.OleDb.OleDbDataReader
> Dim ExcelCommand As System.Data.OleDb.OleDbCommand
>
> MyConnection = New System.Data.OleDb.OleDbConnection( _
> "provider=Microsoft.Jet.OLEDB.4.0; " & _
> "data source=C:\Program
> Files\97CS\SelfInspect\CheckList\NewCheckList.XLS;
> "
> & _
> "Extended Properties=Excel 8.0;")
>
> Dim myTable As System.Data.DataTable
> 'Object reference not set to an instance of an object.
> myDataReader = ExcelCommand.ExecuteReader
> Dim myRow As DataRow = myTable.NewRow
>
> While myDataReader.Read
> myRow.Item("dbmFilterList") = myDataReader.GetData(0)
> myRow.Item("dbmCheckList") = myDataReader.GetData(1)
> myRow.Item("dbmNumber") = myDataReader.GetData(2)
> myRow.Item("dbmQuestion") = myDataReader.GetData(3)
> myRow.Item("dbmReference") = myDataReader.GetData(4)
> ODAAddItems.Update(DsAddItems)
> EndWhile
>
>


Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Islam Elkhayat | last post by:
In my C# Web Application I need to fill a textbox with DataReader and use a Next Button to view next value... I created the Datareader in the Page_Load but everytime it get result of the First...
10
by: KeithRaginF | last post by:
Hello I am trying to return the contents of an Excel file. However, I don't want to just redirect the request to the Excel file since it does not reside in a location where that is appropriate. ...
6
by: Steve Richter | last post by:
I am getting error in a vbscript: ActiveX component cant create object: Excel.Application. The vbscript code is: Dim objExcel Set objExcel = CreateObject("Excel.Application") I am pretty...
0
by: brix_zx2 | last post by:
I have an Excel Spreadsheet I want to import the records (5 fields) into an access 2000 DB. Went on the net looking and found stuff for SQL (which I don't know a thing about) and now I'm confused....
7
by: Varangian | last post by:
Hi all, the question I want to ask if the conversion of a DataReader to a Table looping through the DataReader is better than using the Fill Method of the DataAdapter... I'm asking because...
20
by: fniles | last post by:
I am using VB.NET 2003, SQL 2000, and SqlDataReader. As I read data from tblA, I want to populate tblB. I use SQLDataReader for both tables. I do not use thread. When I ExecuteReader on tblB, I...
2
Pittaman
by: Pittaman | last post by:
Hello, Sorry about the title, I had a hard time explaining this. I've done a little trick to solve a problem I was having with this third party control, and was wondering if anyone here could...
2
by: news.microsoft.com | last post by:
Not sure the best group to post to, so sorry for the cross post :(. There are several posts out there of how to automate excel from .net, i.e in the sample below, they are using Excel 9.0......
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.