Input string was not in a correct format (Paging)

R

RelaxoRy

{
Line 47: sqlConnection1.Open();
Line 48: myReader = currentSqlCommand.ExecuteReader();
Line 49:
Line 50: DataGrid1.AllowCustomPaging=true;

It hangs on line 48 with the subject error. I have a feeling it's
because of the line below :

cmdNext.Parameters["@productid"].Value = "";
Like do i have to somehow convert it to an int somewhere?

-- Code extract

private void Page_Load(object sender, System.EventArgs e)

{
if (!IsPostBack)
{
cmdNext.Parameters["@productid"].Value = "";
CurrentPage = 0;
FillGrid(cmdNext);
}
}
private void FillGrid(SqlCommand currentSqlCommand)
{
sqlConnection1.Open();
myReader = currentSqlCommand.ExecuteReader();
DataGrid1.AllowCustomPaging=true;
DataGrid1.VirtualItemCount=100;
DataGrid1.CurrentPageIndex=0;
DataGrid1.PageSize=10;

DataGrid1.DataSource = myReader;
DataGrid1.DataBind();
myReader.Close();
sqlConnection1.Close();

ViewState["CurrentPage"] = CurrentPage;
ViewState[CurrentPage.ToString()] = DataGrid1.Items[0].Cells[0].Text;

if (DataGrid1.Items.Count < DataGrid1.PageSize)
{
btnNext.Enabled = false;
}
}
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

What are you trying to achieve by doing this?
cmdNext.Parameters["@productid"].Value = "";

I assume "@productid" is a kind of primary key which is usually an int or a
GUID. Obviously, you cannot assign an empty string to a parameter of type
int. You should probably consider passing DBNull instead, or not passing
this parameter at all? (provided that the stored procedure at the SQL
back-end can properly handle missing parameters)

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

RelaxoRy said:
{
Line 47: sqlConnection1.Open();
Line 48: myReader = currentSqlCommand.ExecuteReader();
Line 49:
Line 50: DataGrid1.AllowCustomPaging=true;

It hangs on line 48 with the subject error. I have a feeling it's
because of the line below :

cmdNext.Parameters["@productid"].Value = "";
Like do i have to somehow convert it to an int somewhere?

-- Code extract

private void Page_Load(object sender, System.EventArgs e)

{
if (!IsPostBack)
{
cmdNext.Parameters["@productid"].Value = "";
CurrentPage = 0;
FillGrid(cmdNext);
}
}
private void FillGrid(SqlCommand currentSqlCommand)
{
sqlConnection1.Open();
myReader = currentSqlCommand.ExecuteReader();
DataGrid1.AllowCustomPaging=true;
DataGrid1.VirtualItemCount=100;
DataGrid1.CurrentPageIndex=0;
DataGrid1.PageSize=10;

DataGrid1.DataSource = myReader;
DataGrid1.DataBind();
myReader.Close();
sqlConnection1.Close();

ViewState["CurrentPage"] = CurrentPage;
ViewState[CurrentPage.ToString()] = DataGrid1.Items[0].Cells[0].Text;

if (DataGrid1.Items.Count < DataGrid1.PageSize)
{
btnNext.Enabled = false;
}
}
 
R

relaxory

I'm trying to successfully inplement a quick and easy form of paging
closely following a walkthrough supplied on the MSDN cd's titled
"Creating Paged data access using a web forms page".

cmdNext.Parameters["@productid"].Value = ""; is actually in the
walkthrough, so it seems odd that the author made an error (although not
out of the question).
 

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