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
exist like the orginal statement does. The thing I don't get is that I'm
using the exact same order of things with the select statement as with the
statement that uses the insert into with values parameter. I just don't get
it????

cmd.CommandText =
"Insert into 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) " +
"Values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '"
+ Global.CompanyID + "')";



By the way, why do I need to have the drCustomers[x]["SHIP2_ID"] parametized
when it's part of the where clause?



"Nicholas Paldino [.NET/C# MVP]" wrote:

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: Display Problems
    ... If it shows up in the GUI, it is there, and must be present ... Or issue the command; ... > and got the error message file or folder not found. ... in the midst of the frustration, by all means, vent away. ...
    (alt.os.linux.suse)
  • Re: Display Problems
    ... If it shows up in the GUI, it is there, and must be present ... > get the error message that you, in fact, did get. ... > Or issue the command; ... > in the midst of the frustration, by all means, vent away. ...
    (alt.os.linux.suse)
  • RE: Run a Stored Procedure from Excel
    ... get a single line multiple command working from ... I changed all the Charto Charand found that I got an error message ... Dim cnnDW As ADODB.Connection ... Dim rsDW As ADODB.Recordset ...
    (microsoft.public.excel.programming)
  • Re: A form that could no longer be opened for modification
    ... You CANNOT get that error message from the USE command. ... file corruption should be the reason. ... I can of course get from backup and lost some works, ...
    (microsoft.public.fox.vfp.forms)
  • Re: explorer quits unexpectedly
    ... Try to register the DLL that may help and scan for Malwares on your ... 1= Open a RUN Command and type the following; ... I can't see how any of those could cause a fault when attemting to ... Read this article on the fault error message it may apply to you if you have ...
    (microsoft.public.windows.inetexplorer.ie6.browser)