Environment: Windows XP
Using MS Visual Studio 2005
SQL Server 2000
My Question: I decided to change an integer column in my SQL server table to a VARCHAR(32). I changed my SQL server stored procedure to accept a varchar(32) input parameter and I changed the VB.net application to correctly Add the varchar parameter to my insert command.
I'll include snippet in a moment.
Problem: The error message tells me that it recognizes my variable input as VARCHAR but tries to convert it to INT.
I dimension the variables as string in my VB.net code.
Populate it with the text data and then pass it to the stored procedure call from VB. When this didn't work I tried a test and actually sent integer values instead of text. And this worked fine. The SQL insert correctly inserted integer values into my VARCHAR fields.
REQUEST: Your help is appreciated. I hope you can spot something that explains why it won't take the TEXT values.
SNIPPET:
From VB.net
Dim txtChar1 as String
Dim cmd As New SqlClient.SqlCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "pr_test"
cmd.Parameters.Add("@CharTEXT", SqlDbType.VarChar, 32)
Dim SQlconn As New SqlClient.SqlConnection
cmd.Connection = SQlconn
SQlconn.Open()
cmd4.Parameters("@CharTEXT").Value = String.Format(txtChar1)
cmd.ExecuteNonQuery()
From: SQL Server
ALTER PROCEDURE dbo.pr_test
(
@CharTEXT varchar(32),
)
AS
SET NOCOUNT OFF;
BEGIN
INSERT INTO TestTable (CharacteristicID)
VALUES (@CharTEXT)
END
RETURN
ERROR MESSAGE:
Syntax Error converting the VARCHAR VALUE 'MYINPUT' to a column of datatype int
By the way, the Table has a varchar(32) data item.
So I tried some various formatting attempts to try to get my Visual Basic. NET code to accept the varchar text. But most reasonable solutions don't seem to work. You'll will notice I'm using String.Format(txtChar1). I tried txt.Char1.TEXT but intellisense wouldn't allow it. Any ideas appreciated.
Using MS Visual Studio 2005
SQL Server 2000
My Question: I decided to change an integer column in my SQL server table to a VARCHAR(32). I changed my SQL server stored procedure to accept a varchar(32) input parameter and I changed the VB.net application to correctly Add the varchar parameter to my insert command.
I'll include snippet in a moment.
Problem: The error message tells me that it recognizes my variable input as VARCHAR but tries to convert it to INT.
I dimension the variables as string in my VB.net code.
Populate it with the text data and then pass it to the stored procedure call from VB. When this didn't work I tried a test and actually sent integer values instead of text. And this worked fine. The SQL insert correctly inserted integer values into my VARCHAR fields.
REQUEST: Your help is appreciated. I hope you can spot something that explains why it won't take the TEXT values.
SNIPPET:
From VB.net
Dim txtChar1 as String
Dim cmd As New SqlClient.SqlCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "pr_test"
cmd.Parameters.Add("@CharTEXT", SqlDbType.VarChar, 32)
Dim SQlconn As New SqlClient.SqlConnection
cmd.Connection = SQlconn
SQlconn.Open()
cmd4.Parameters("@CharTEXT").Value = String.Format(txtChar1)
cmd.ExecuteNonQuery()
From: SQL Server
ALTER PROCEDURE dbo.pr_test
(
@CharTEXT varchar(32),
)
AS
SET NOCOUNT OFF;
BEGIN
INSERT INTO TestTable (CharacteristicID)
VALUES (@CharTEXT)
END
RETURN
ERROR MESSAGE:
Syntax Error converting the VARCHAR VALUE 'MYINPUT' to a column of datatype int
By the way, the Table has a varchar(32) data item.
So I tried some various formatting attempts to try to get my Visual Basic. NET code to accept the varchar text. But most reasonable solutions don't seem to work. You'll will notice I'm using String.Format(txtChar1). I tried txt.Char1.TEXT but intellisense wouldn't allow it. Any ideas appreciated.