G
Guest
I am having difficulty calling a stored procedure from VB.Net that has a Bit
parameter. To try and figure it out, I have created some tests. The SQL SP
looks like this:
CREATE procedure up_insert_test
@value bit as
insert into tblTest(field1) values(@value)
And the table has two fields. The first is ID which is an indentity field,
and the second is Field1 that is just a nullable Bit field.
Here is my VB Code:
Dim cn As SqlConnection
Dim cmd As SqlCommand
cn = New SqlConnection(g_DBConnection)
cn.Open()
If cn.State = ConnectionState.Open Then
cmd = New SqlCommand("up_insert_test")
cmd.Connection = cn
Dim p As New SqlParameter("@value", SqlDbType.Bit)
p.Value = 1
cmd.Parameters.Add(p)
cmd.ExecuteNonQuery() 'Fails here!!!!!
cn.Close()
End If
Everytime I get to the ExecuteNonQuery I get the followning error:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred
in system.data.dll
Additional information: System error.
If anyone can give me a hand, I would greatly appreciate it.
Thanks,
Rob
parameter. To try and figure it out, I have created some tests. The SQL SP
looks like this:
CREATE procedure up_insert_test
@value bit as
insert into tblTest(field1) values(@value)
And the table has two fields. The first is ID which is an indentity field,
and the second is Field1 that is just a nullable Bit field.
Here is my VB Code:
Dim cn As SqlConnection
Dim cmd As SqlCommand
cn = New SqlConnection(g_DBConnection)
cn.Open()
If cn.State = ConnectionState.Open Then
cmd = New SqlCommand("up_insert_test")
cmd.Connection = cn
Dim p As New SqlParameter("@value", SqlDbType.Bit)
p.Value = 1
cmd.Parameters.Add(p)
cmd.ExecuteNonQuery() 'Fails here!!!!!
cn.Close()
End If
Everytime I get to the ExecuteNonQuery I get the followning error:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred
in system.data.dll
Additional information: System error.
If anyone can give me a hand, I would greatly appreciate it.
Thanks,
Rob