Dump OLEDbCommand

  • Thread starter Thread starter Peter Carlson
  • Start date Start date
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
 
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
 
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!)
 
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!)
 
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
 
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
 
Back
Top