By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 1,990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

Can execute a query with multiple parameters

P: n/a
Dim cn As SqlConnection = New SqlConnection("<ConnStr>")
cn.Open()
Dim cmd As SqlCommand = New SqlCommand("scsp_Stored_Proc", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim pc As SqlParameterCollection = cmd.Parameters

pc.Add("@Param1", Param1Val)
pc.Add("@Param2", Param2Val)
If Param3Val <> 0 Then
pc.Add("@Param3", Param3Val)
Else
pc.Add("@Param4", Param4Val)
End If
cmd.ExecuteNonQuery()

what am I doing wrong?

It's erroring out on the last line:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred
in system.data.dll

Additional information: System error.
Mar 30 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I got it. It was expecting nulls. I used System.DBNull.Value for the other
params in the If..then condition.
"mrmagoo" <-> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Dim cn As SqlConnection = New SqlConnection("<ConnStr>")
cn.Open()
Dim cmd As SqlCommand = New SqlCommand("scsp_Stored_Proc", cn)
cmd.CommandType = CommandType.StoredProcedure
Dim pc As SqlParameterCollection = cmd.Parameters

pc.Add("@Param1", Param1Val)
pc.Add("@Param2", Param2Val)
If Param3Val <> 0 Then
pc.Add("@Param3", Param3Val)
Else
pc.Add("@Param4", Param4Val)
End If
cmd.ExecuteNonQuery()

what am I doing wrong?

It's erroring out on the last line:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

Additional information: System error.

Mar 30 '06 #2

P: n/a
I think you should have looked at the inner exception.. that would
have told you the exact problem.

Mar 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.