SQL Data Types

B

BrianDH

This is new to me. I am trying to call a SP (MS SQL) and pass different data
types. I know in SQL you handel these data types diffent in your string

Public Shared Function GetGridDataSet(ByVal val1 As Integer, ByVal val2 As
String) As DataSet
Dim UserData As DataSet
Dim myConnection As SqlConnection
Dim myCommand As SqlDataAdapter
myConnection = New SqlConnection(ConnectionString)
myCommand = New SqlDataAdapter("Exec ap_ExpressOnLineCheckoutForASP
'" + val1 + "','" + val2 + "'", myConnection)
UserData = New DataSet
myCommand.Fill(UserData, "DealConfirm")
myConnection.Close()
Return UserData
End Function
I am getting this error:" Input string was not in a correct format."

Can someone point me to a link that can help me get my sting right (Date,
Int, Dbl,)

Thanks
 
M

Matt

Your val1 is an integer. VB.NET doesn't convert an Integer to a String
automatically when using + to concatenate. Either change + to & or use
val1.ToString() to get String value.
 
B

BrianDH

OK no i awant it to be an Int. The SP is looking for an Int and a String.

I'll try the + to &.. but does the '" val1 '" or ' val ' have anything to do
with it like when writing a SQL statment?
 
J

Jeff Johnson [MVP: VB]

OK no i awant it to be an Int. The SP is looking for an Int and a String.
I'll try the + to &.. but does the '" val1 '" or ' val ' have anything to do
with it like when writing a SQL statment?

You are building a string to supply to the SqlDataAdapter. You are
attempting to concatenate a variable of type Integer into that string. You
cannot do that with the + operator without explicitly converting that
variable to a string.

This has nothing to do with whether SQL Server will interpret the parameters
of the SQL stored procedure call as ints or varchars or whatever. The is
controlled solely by whether those values are in apostrophes or not.
 
B

BrianDH

OK found my answer.
Dim CN As Data.SqlClient.SqlConnection
Dim ConnectionString As String = "Server=SQLSERVER bla bla bla"
CN = New SqlClient.SqlConnection(ConnectionString)
CN.Open()
Dim cmd As New SqlClient.SqlCommand("ap_ExpressOnLineCheckoutForASP", CN)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@intDealTypeID", SqlDbType.Int).Value = val1
cmd.Parameters.Add("@intProductTypeID", SqlDbType.VarChar).Value = val2
Dim da As New SqlClient.SqlDataAdapter(cmd)
Dim ds As New DataSet
da.Fill(ds, "Products")
Return ds
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top