473,387 Members | 1,529 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Databinding a datagrid to a stored procedure..

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 /--
Nov 18 '05 #1
1 1512
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

"Stu Lock" <s.****@cergis.com> wrote in message
news:Oq*************@TK2MSFTNGP11.phx.gbl...
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 /--

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Max | last post by:
Is it possible or more effecient to use a stored procedure to populate a datagrid when using datagrid or custom paging? Is it (ADO.NET?) pulling the entire table into the dataset or is it just...
2
by: Mo | last post by:
Hi, I have a page that is split into two frames: top and bottom. The top page is a search parameters page and the bottom is the results page; which holds the datagrid. The search page sends the...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
6
by: Shawn | last post by:
Hi. I already have a datagrid where I'm using paging. I have a stored procedure that fills a temp table with 200-500 rows and then sends back 10 records at the time. When I go to page 2 the SP...
8
by: Jeff | last post by:
Hi - I'm having trouble Databinding a SQLDataReader to a DataGrid control. I have an ASP.NET web page accessing a SQL database. I've used VS to build the app and stored it in a directory of...
1
by: .Net Sports | last post by:
i have an aliased column in an sql statement that works fine when displaying its output in a datagrid, but when I transfer the sql statement into a stored procedure , the datagrid can't see it. I...
6
by: Jim | last post by:
Can someone, please, show me how to display the results of a stored procedure in a VB.NET datagrid on a winform? I'm a newbie. Here's my SQL 2000 stored precedure that returns the status of...
11
by: Fred Nelson | last post by:
I have an application in which it would be VERY beneficial if I could obtain the names of the colums in a datagrid. For example dim datagrid1 as new datagrid datagrid1.datasource = (stored...
1
by: Sharon | last post by:
Hello All, Is it possible to update Sql Table through DataGrid. I have a DataGrid which is being populated through a stored procedure, all i wanted to do is to update one field...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.