|
-
Oct 24th, 2003, 01:39 PM
#1
Thread Starter
Hyperactive Member
SQL statement
What is wrong with this...
' define and get the Customers Master
Dim cmdSQL_C As New SqlCommand("Select Top 1 * from Customers where CustomerID = @CustomerID")
cmdSQL_C.Connection = conSQL
cmdSQL_C.Parameters.Add("@CustomerID", System.Data.SqlDbType.Int)
cmdSQL_C.Parameters("@CustomerID").Value = TextBox3.Text 'has a valid key value
conSQL.Open()
Rdr = cmdSQL_C.ExecuteReader()
Rdr.Read()
At the .ExecuteReader I get the error :
An unhandled exception of type 'System.FormatException' occurred in system.data.dll
Additional information: Input string was not in a correct format
The key to Customers is nchar(5).
When I use this same set of code for a key that numeric .. all is fine... What's up???
gollnick
-
Oct 24th, 2003, 02:09 PM
#2
Its probably just a casting problem try changing this line:
VB Code:
cmdSQL_C.Parameters("@CustomerID").Value = Interger.Parse(TextBox3.Text)
-
Oct 24th, 2003, 02:15 PM
#3
Thread Starter
Hyperactive Member
Tried that.. Does not like "Interger" ... If this is a character key value .. should it be a numeric assignment?
-
Oct 24th, 2003, 02:24 PM
#4
-
Oct 24th, 2003, 02:26 PM
#5
Yeah that was my bad I meant Integer my fingers just got going a lil TOO fast and I threw in an extra r.
-
Oct 24th, 2003, 02:27 PM
#6
Thread Starter
Hyperactive Member
Yupper .. Integer....... still .. with a charactor key?
-
Oct 24th, 2003, 02:29 PM
#7
If its not a numeric assignment then you set up the parameter wrong. This line sets the Parameter to an integer type:
cmdSQL_C.Parameters.Add("@CustomerID", System.Data.SqlDbType.Int)
So if it shouldn't be an integer then you'll need to change the parameter declaration to whatever it should really be.
What do you mean by character key? What is the value you are passing in?
-
Oct 24th, 2003, 02:33 PM
#8
Thread Starter
Hyperactive Member
Duh .....
cmdSQL_C.Parameters.Add("@CustomerID", System.Data.SqlDbType.NChar) .... works.....
Thanks to all....
-
Oct 24th, 2003, 02:33 PM
#9
Really there is no need for the parameter you can include it right in the SQL statement since they are created at the same time:
VB Code:
Dim sql_str As String=String.Format("Select Top 1 * from Customers where CustomerID = '{0}'",TextBox3.Text)
Dim cmdSQL_C As New SqlCommand(sql_str)
conSQL.Open()
Although if the value is numeric then remove the ' and ' around the {0}.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|