More Access files with C# and OLEDB provider

E

Eric Kiernan

I'm having two problems. In my tables I have an autoincrement field
called ID, and the type is long ( in Access ). When I try to load it
through c# i have something like this when i try to load the data.
objConnection.Open();
objCommand.CommandText = "SELECT * from BudgetSpending";
objCommand.CommandType = CommandType.Text;
// why i don't have to specify OleDBDataReader reader is beyond me.
reader = objCommand.ExecuteReader();
while ( reader.Read()) {
long ID = (long) reader["ID"];

and c# complains that it can't cast the field into a long. What do i
cast it to? Everything else casts and loads fine.

My second problem is i really want to do something like this

tempTable = "select * from Budget"
// execute a command to perform the select and return the result set to
tempTable
if ( tempTable.Count == 0 )
// then do an insert

All i seem to to have is an ExecuteNonQuery, and an ExecuteReader. I
can't seem to get a count from a dataReader. Help! I know i used to be
able to do something like this in VB6.
 
E

Eric Kiernan

Eric said:
I'm having two problems. In my tables I have an autoincrement field
called ID, and the type is long ( in Access ). When I try to load it
through c# i have something like this when i try to load the data.
objConnection.Open();
objCommand.CommandText = "SELECT * from BudgetSpending";
objCommand.CommandType = CommandType.Text;
// why i don't have to specify OleDBDataReader reader is beyond me.
reader = objCommand.ExecuteReader();
while ( reader.Read()) {
long ID = (long) reader["ID"];

and c# complains that it can't cast the field into a long. What do i
cast it to? Everything else casts and loads fine.

My second problem is i really want to do something like this

tempTable = "select * from Budget"
// execute a command to perform the select and return the result set
to tempTable
if ( tempTable.Count == 0 )
// then do an insert

All i seem to to have is an ExecuteNonQuery, and an ExecuteReader. I
can't seem to get a count from a dataReader. Help! I know i used to be
able to do something like this in VB6.

On my second problem i suppose I could do something like
if ( reader.HasRows )
// do an update
else
// do an insert.
 
E

Eric Kiernan

I take it back. I can't get any data to load, no matter how I cast it.


Eric said:
Eric said:
I'm having two problems. In my tables I have an autoincrement field
called ID, and the type is long ( in Access ). When I try to load it
through c# i have something like this when i try to load the data.
objConnection.Open();
objCommand.CommandText = "SELECT * from BudgetSpending";
objCommand.CommandType = CommandType.Text;
// why i don't have to specify OleDBDataReader reader is beyond me.
reader = objCommand.ExecuteReader();
while ( reader.Read()) {
long ID = (long) reader["ID"];

and c# complains that it can't cast the field into a long. What do i
cast it to? Everything else casts and loads fine.

My second problem is i really want to do something like this

tempTable = "select * from Budget"
// execute a command to perform the select and return the result
set to tempTable
if ( tempTable.Count == 0 )
// then do an insert

All i seem to to have is an ExecuteNonQuery, and an ExecuteReader. I
can't seem to get a count from a dataReader. Help! I know i used to
be able to do something like this in VB6.

On my second problem i suppose I could do something like
if ( reader.HasRows )
// do an update
else
// do an insert.
 
E

Eric Kiernan

Eric said:
I take it back. I can't get any data to load, no matter how I cast it.


Eric said:
Eric said:
I'm having two problems. In my tables I have an autoincrement field
called ID, and the type is long ( in Access ). When I try to load it
through c# i have something like this when i try to load the data.
objConnection.Open();
objCommand.CommandText = "SELECT * from BudgetSpending";
objCommand.CommandType = CommandType.Text;
// why i don't have to specify OleDBDataReader reader is beyond me.
reader = objCommand.ExecuteReader();
while ( reader.Read()) {
long ID = (long) reader["ID"];

and c# complains that it can't cast the field into a long. What do i
cast it to? Everything else casts and loads fine.

My second problem is i really want to do something like this

tempTable = "select * from Budget"
// execute a command to perform the select and return the result
set to tempTable
if ( tempTable.Count == 0 )
// then do an insert

All i seem to to have is an ExecuteNonQuery, and an ExecuteReader. I
can't seem to get a count from a dataReader. Help! I know i used to
be able to do something like this in VB6.

On my second problem i suppose I could do something like
if ( reader.HasRows )
// do an update
else
// do an insert.

I cast everything to an object, and then the locals window told me what
kind of object it was. For instance, an Access double is a C# float;
 
E

Eric Kiernan

Eric said:
Eric said:
I take it back. I can't get any data to load, no matter how I cast it.


Eric said:
Eric Kiernan wrote:
I'm having two problems. In my tables I have an autoincrement field
called ID, and the type is long ( in Access ). When I try to load
it through c# i have something like this when i try to load the data.
objConnection.Open();
objCommand.CommandText = "SELECT * from BudgetSpending";
objCommand.CommandType = CommandType.Text;
// why i don't have to specify OleDBDataReader reader is beyond me.
reader = objCommand.ExecuteReader();
while ( reader.Read()) {
long ID = (long) reader["ID"];

and c# complains that it can't cast the field into a long. What do
i cast it to? Everything else casts and loads fine.

My second problem is i really want to do something like this

tempTable = "select * from Budget"
// execute a command to perform the select and return the result
set to tempTable
if ( tempTable.Count == 0 )
// then do an insert

All i seem to to have is an ExecuteNonQuery, and an ExecuteReader.
I can't seem to get a count from a dataReader. Help! I know i used
to be able to do something like this in VB6.

On my second problem i suppose I could do something like
if ( reader.HasRows )
// do an update
else
// do an insert.

I cast everything to an object, and then the locals window told me what
kind of object it was. For instance, an Access double is a C# float;
I figured everything out. Sorry for all the posting.
 
G

Gregory A. Beamer

I figured everything out. Sorry for all the posting.

White board? Newsgroup? if you end up with the solution, I guess either
works. ;-)

Peace and Grace,

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top