Re: Problem using command.parameters



Johnny,

Assuming the order is correct, I would look at what the following is returning:

drCustomers[x]["SHIP2_ID"]

As you are just appending it in the string, when in reality, you really should be parameterizing that as well.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"Johnny" <Johnny@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:B3AE7C83-F3E7-4837-80A9-DDF90634681E@xxxxxxxxxxxxxxxx
I need to get data from a sql server database and insert records into a sqlce
database if they do not already exist in the sqlce database. I have written
the code below but I'm getting an error message when the cmd.Prepare() line
is executed. The error message is - "The conversion is not supported. [ Type
to convert from (if known) = int, Type to convert to (if known) =
uniqueidentifier ]"}

I have compared the ordinal position of each parameter to the SqlDbType and
they all match. I don't have any idea why I'm getting the error message or
how to debug it at this point. Any help would be much appreciated.


cmd.CommandText =
"Insert VMI_CUST (CUST_ID, SHIP2_ID, CUST_NO,
QUICK_SCAN, ALLOW_DUPLICATE_SCANS, SIGNATURE_REQUIRED, " +
"VALIDATE_MANDATORY_ITEMS, PO_TYPE, CUST_PO,
LAST_CHANGE_DATE, RELEASE_NO, LAST_SYNC_DATE, COMPANY_ID) " +
"Select " +
"?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " +
"'" + Global.CompanyID + "' " +
"FROM vmi_controls " +
"WHERE vmi_controls.company_id = '" +
Global.CompanyID + "'"; //+
" AND NOT EXISTS " +
"(SELECT cust_id FROM vmi_cust WHERE
cust_id = '" + drCustomers[x]["CUST_ID"] + "'" +
" and ship2_id =
'" + drCustomers[x]["SHIP2_ID"] + "'" +
" and company_id =
'" + Global.CompanyID + "')";



cmd.Parameters.Clear();

cmd.Parameters.Add(new SqlCeParameter("CUST_ID",
SqlDbType.UniqueIdentifier));
cmd.Parameters.Add(new SqlCeParameter("SHIP2_ID",
SqlDbType.UniqueIdentifier));
cmd.Parameters.Add(new SqlCeParameter("CUST_NO",
SqlDbType.NVarChar));
cmd.Parameters.Add(new SqlCeParameter("QUICK_SCAN",
SqlDbType.NVarChar));
cmd.Parameters.Add(new
SqlCeParameter("ALLOW_DUPLICATE_SCANS", SqlDbType.NVarChar));
cmd.Parameters.Add(new
SqlCeParameter("SIGNATURE_REQUIRED", SqlDbType.NVarChar));
cmd.Parameters.Add(new
SqlCeParameter("VALIDATE_MANDATORY_ITEMS", SqlDbType.NVarChar));
cmd.Parameters.Add(new SqlCeParameter("PO_TYPE",
SqlDbType.NVarChar));
cmd.Parameters.Add(new SqlCeParameter("CUST_PO",
SqlDbType.NVarChar));
cmd.Parameters.Add(new
SqlCeParameter("LAST_CHANGE_DATE", SqlDbType.DateTime));
cmd.Parameters.Add(new SqlCeParameter("RELEASE_NO",
SqlDbType.NVarChar));
cmd.Parameters.Add(new
SqlCeParameter("LAST_SYNC_DATE", SqlDbType.DateTime));

cmd.Prepare();

.



Relevant Pages

  • Re: SQL Server CE error, No data exists for the row/column
    ... > I'm simply trying to check the login parameters from a SQLCE database on ... > the Pocket PC. ... > I can see the database, I can query the data type and more, I just can't ... > error message. ...
    (microsoft.public.pocketpc.developer)
  • Re: Problem using command.parameters
    ... I changed the command text to the following and it works great but I'm not ... getting the results I need because I'm not filtering out values that already ... database if they do not already exist in the sqlce database. ... I don't have any idea why I'm getting the error message ...
    (microsoft.public.dotnet.languages.csharp)
  • Pocket PC Error
    ... I got this error when I tried to create a table in sqlce database: ... Here is the error message: ... "An unhandled exception of type 'System.Data.SqlServerCe.SqlCeException' ... Sharon ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Problem with fread()
    ... The error message at the bottom says ... this was a manual edit of the error output. ... \Dave\blah.php in reality. ...
    (comp.lang.php)