Databinding a datagrid to a stored procedure..

S

Stu Lock

Hi,

I have converted some code to try and databind a datagrid using a stored
procedure. Basically I am now naming the SP, setting the command type and
adding and loading a prameter instead of just passing an SQL string.

When I run the code below I get the error "Input string was not in a correct
format." on the 'da.Fill(ds, "Prices")' line....and I have no idea why!

Can anyone point me in the right direction.

Thanks in advance,

Stu

--/ snip /--

Dim cn = New SqlConnection("MyConnString")
cn.Open()

Dim cmd As New SqlCommand("SP_ListAllPrices", cn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@Countries_ID", SqlDbType.Int)
cmd.Parameters("@Countries_ID").Value = ddlCountries_ID.SelectedValue

Dim da = New SqlDataAdapter(cmd)
Dim ds = New DataSet
da.Fill(ds, "Prices") <<<<<<<<<<<<<<< error
DataGrid1.DataSource = ds
DataGrid1.DataBind()
da = Nothing
cn.Close()

--/ snip /--
 
K

Karl

Stu:
ds.Fill(ds, "Price") does a lot of things...so the error isn't necessary
with the syntax of that line, but with something that's being executed
because of that line. a Fill() command actually causes the stored procedure
to get executed on SQL Server, and that's what's actually causing the error.

Specificically, the error has to do with ddlCountries_ID.SelectedValue
(anyways, that's my guess). I'm thinking the value is either an empty
string or not an integer. Try to cint() the value..

Karl
 

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

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,816
Latest member
nipsseyhussle

Latest Threads

Top