datatable

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

How do you form a datatable programatically, the following does not work,

OleDbConnection conn = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source="c:\\Test.mdb");
conn.Open();

OleDbDataAdapter dadp = new OleDbDataAdapter("SELECT Company.Company_No,
Company.Company_Name], Company.Address
"FROM Company", conn);

DataTable m_datatable= new DataTable();
dadp.Fill(m_datable,"newdata");

The last line fails, why?
 
Please always mention the error message so that we are sure.

For now your code doesn't compile as m_datable is not m_datatable but I have
no idea if this is a typo in your postor if you have the same errror in your
actual code (this is where the exact error message could have been
helpfull)... You also have other errors in your code (once again not sure if
typo or actual errors).
 
I think they are just typo s but let me see if I can correct what I know abt
and see if you see any other errors.

OleDbConnection conn = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source="c:\\Test.mdb");
conn.Open();

OleDbDataAdapter dadp = new OleDbDataAdapter("SELECT Company.Company_No, "+
"Company.Company_Name, Company.Address "+
"FROM Company", conn);

DataTable m_datatable= new DataTable();
dadp.Fill(m_datatable,"newdata");

Patrice said:
Please always mention the error message so that we are sure.

For now your code doesn't compile as m_datable is not m_datatable but I have
no idea if this is a typo in your postor if you have the same errror in your
actual code (this is where the exact error message could have been
helpfull)... You also have other errors in your code (once again not sure if
typo or actual errors).

--
Patrice

Dave said:
How do you form a datatable programatically, the following does not work,

OleDbConnection conn = new OleDbConnection(
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source="c:\\Test.mdb");
conn.Open();

OleDbDataAdapter dadp = new OleDbDataAdapter("SELECT Company.Company_No,
Company.Company_Name], Company.Address
"FROM Company", conn);

DataTable m_datatable= new DataTable();
dadp.Fill(m_datable,"newdata");

The last line fails, why?

.
 
What if using just dadp.Fill(m_datatable); ?

With dadp.Fill(m_datatable,"newdata"), I really don't see what "newdata"
could be. Actually if I check the doc I see that the closest overload would
be having a recordset object as a second parameter ?

If it's still not that PLEASE always tell explicitely what is the error
message. This is really the primary information that should be used when you
get an error...

And actually I tried the code and this is exactly the error I get, it
complains the parameter is not an ADOB.Recordset or an ADOB.Record.

if this is really what you get, you can see having the error message in your
first post would have been allow to solve this much quicker for both of
us...
 
Thanks! Patrice that solved my probloem! I should not have included the
"newdata" After taking that out everything worked fine.
 
Back
Top