Dump OLEDbCommand

P

Peter Carlson

I am building a sql update to access database with the following code

String sql = "Update Homes set "
+ "Appearance=?, L_Area=?, Beds=?, FacilityName=?,
[Full]=?, "
+ "L_Map=?, [Open AL]=?, [Open ALZ]=?, [Open B+C]=?,
[Payment Rating]=?, [Placement Rating]=?, "
+ "[Last Update By]=?, [Last Visit By]=?, Website=?,
[Public Notes]=?, [Private Notes]=?, Remarks=?"
+ " where ID=" + nHomeID;

OleDbCommand cmd = new OleDbCommand(sql, con);

cmd.Parameters.AddWithValue("@FacilityName", tbName.Text);
cmd.Parameters.AddWithValue("@Website", tbWebsite.Text);
... more AddWithValues...
cmd.ExecuteNonQuery();

somewhere along the way I have a value that is not matching error is:
Data Type Mismatch

when I run cmd.CommandText, I get the sql with the ? still in it. How
can I dump the actual sql so I can copy / paste into access to see what
field is giving me problems.

Peter
 
C

Chris

I am building a sql update to access database with the following code

String sql = "Update Homes set "
+ "Appearance=?, L_Area=?, Beds=?, FacilityName=?,
[Full]=?, "
+ "L_Map=?, [Open AL]=?, [Open ALZ]=?, [Open B+C]=?,
[Payment Rating]=?, [Placement Rating]=?, "
+ "[Last Update By]=?, [Last Visit By]=?, Website=?,
[Public Notes]=?, [Private Notes]=?, Remarks=?"
+ " where ID=" + nHomeID;

OleDbCommand cmd = new OleDbCommand(sql, con);

cmd.Parameters.AddWithValue("@FacilityName", tbName.Text);
cmd.Parameters.AddWithValue("@Website", tbWebsite.Text);
... more AddWithValues...
cmd.ExecuteNonQuery();

somewhere along the way I have a value that is not matching error is:
Data Type Mismatch

when I run cmd.CommandText, I get the sql with the ? still in it. How
can I dump the actual sql so I can copy / paste into access to see what
field is giving me problems.

Peter

Run a trace using Sql Profiler and you can see exactly what is being
sent to the server.

Chris
 
J

Jeff Johnson

Run a trace using Sql Profiler and you can see exactly what is being
sent to the server.

But wouldn't he have to change the provider string in order for it to talk
to SQL Server, at which point the possibility exists that different SQL
would be generated than for Access/Jet? I assumed he's using Access from
this statement:

(Note to everyone: proper capitalization goes a LONG way!)
 
P

Peter Carlson

yes my apologies it is an Access database.
Peter

Jeff said:
But wouldn't he have to change the provider string in order for it to talk
to SQL Server, at which point the possibility exists that different SQL
would be generated than for Access/Jet? I assumed he's using Access from
this statement:


(Note to everyone: proper capitalization goes a LONG way!)
 
A

Arne Vajhøj

Peter said:
I am building a sql update to access database with the following code

String sql = "Update Homes set "
+ "Appearance=?, L_Area=?, Beds=?, FacilityName=?,
[Full]=?, "
+ "L_Map=?, [Open AL]=?, [Open ALZ]=?, [Open B+C]=?,
[Payment Rating]=?, [Placement Rating]=?, "
+ "[Last Update By]=?, [Last Visit By]=?, Website=?,
[Public Notes]=?, [Private Notes]=?, Remarks=?"
+ " where ID=" + nHomeID;

OleDbCommand cmd = new OleDbCommand(sql, con);

cmd.Parameters.AddWithValue("@FacilityName", tbName.Text);
cmd.Parameters.AddWithValue("@Website", tbWebsite.Text);
... more AddWithValues...
cmd.ExecuteNonQuery();

somewhere along the way I have a value that is not matching error is:
Data Type Mismatch

when I run cmd.CommandText, I get the sql with the ? still in it. How
can I dump the actual sql so I can copy / paste into access to see what
field is giving me problems.

I don't think you can.

But if you make two columns with type in database
and type in C#, then something may turn up.

You may also get better errors by adding parameters
with specific type.

Arne
 
C

Chris

But wouldn't he have to change the provider string in order for it to talk
to SQL Server, at which point the possibility exists that different SQL
would be generated than for Access/Jet? I assumed he's using Access from
this statement:


(Note to everyone: proper capitalization goes a LONG way!)

Sorry, I didn't catch that part about it being Access.

Chris
 

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