Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone!! Im almost there with my project, i decide to change everything and start to scratch ... so can you help me in my error problem quoted :
"Input string was not in a correct format." in which this is my code behind


Line 176: Dim cmd As New SqlClient.SqlCommand("Populatecsv", con) ' create command objects and add parameters
Line 177: With cmd.Parameters
Line 178: .Add("@id", SqlDbType.BigInt, "id")
Line 179: .Add("@srn", SqlDbType.BigInt, "srn")
Line 180: .Add("@srcode", SqlDbType.BigInt, "srcode")

since the id variable is BIGINT how can i convert it to correct its format and take note im using 64bit so i'm must declare Convert.ToInt64 yet i dont know how to start with that

very well appreciated with your help guys thanks in advance :)
Posted

SqlParameterCollection.Add doesn't have a prototype that takes a String, SqlDbType, and String.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.aspx[^]

It may be trying to convert the string to an integer which is where you are getting your problem. If you want to use the "SourceColumn" of the add, you also need to use the prototype that specifies the column size.

http://msdn.microsoft.com/en-us/library/e5xwx8sc.aspx[^]
 
Share this answer
 
Comments
Member 10033107 5-Jun-13 21:13pm    
Hi Ron! thanks for your response.. meaning i need to indicate the value already in my command?? wherein do you have any idea of add a data that expect new value? did you get my point? so there..
Instead of writing:

VB
.Add("@id", SqlDbType.BigInt, "id")


you need to write this:

VB
.Add("@id", SqlDbType.BigInt)


And then you assign the values to the parameters:

VB
cmd.Parameters("@id").Value = id
 
Share this answer
 
Comments
Member 10033107 5-Jun-13 21:17pm    
hey Andrew.. I will try this command lines thanks!! ^^
Member 10033107 5-Jun-13 21:35pm    
i encounter this new error maybe can you help me int this one too.. thanks



Line 196: .Add("@Package", SqlDbType.VarChar, 500, "package")
Line 197: .Add("@PromoCode", SqlDbType.VarChar, 500, "promocode")
Line 198: .Add("@ApplicationDate", SqlDbType.DateTime, "applicationdate")
Line 199: .Add("@PaymentDate", SqlDbType.DateTime, "paymenttype")
Line 200: .Add("@EndorsedDate", SqlDbType.DateTime, "endorseddate")
chaau 5-Jun-13 21:43pm    
There is no overload with a string as a third parameter. Use:
.Add("@ApplicationDate", SqlDbType.DateTime)
I guess you have implemented the syntax of DataAdapter Parameters[^], but you need the syntax for SqlClient.SqlCommand as you have done like this.
VB
Dim cmd As New SqlClient.SqlCommand("Populatecsv", con)


So, refer - Configuring Parameters and Parameter Data Types[^], which has the best example how to do it using SqlClient.SqlCommand.
 
Share this answer
 
v2
Comments
chaau 6-Jun-13 0:36am    
The third parameter in the Add method is not a value. It is a size for the string values
Oh I am sorry. I am updating my Answer now. Thanks a lot.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900