Home > DeveloperSection > Forums > how to pass Sql parameter
Ashish Pandey

Total Post:128

Points:898
Posted on    June-19-2013 4:02 AM

 ADO.Net ADO.Net 
Ratings:


 1 Reply(s)
 858  View(s)
Rate this:
Hi Developers, 

I have created stored procedure that expects one parameter '@order_no', which was not supplied. I am sending parameter to procedure like below

try
{
    con.Open();

    SqlCommand cmd = new SqlCommand("gridalldata", con);
    cmd.Parameters.Add("@order_no", SqlDbType.NVarChar).Value = txt_orderno.Text;

    SqlDataReader dr = cmd.ExecuteReader();

    for (int i = 0; i < dataGridView1.Rows.Count; i++)
    {
        if (dr.HasRows)
        {
            dr.Read();

            dataGridView1.Rows[i].Cells[0].Value = dr[0].ToString();

            dataGridView1.Rows[i].Cells[2].Value = dr[2].ToString();
            dataGridView1.Rows[i].Cells[3].Value = dr[3].ToString();
            dataGridView1.Rows[i].Cells[4].Value = dr[4].ToString();
            dataGridView1.Rows[i].Cells[5].Value = dr[5].ToString();
            dataGridView1.Rows[i].Cells[6].Value = dr[6].ToString();
            dataGridView1.Rows[i].Cells[7].Value = dr[7].ToString();
            dataGridView1.Rows[i].Cells[8].Value = dr[8].ToString();
            dataGridView1.Rows[i].Cells[9].Value = dr[9].ToString();
            dataGridView1.Rows[i].Cells[10].Value = dr[13].ToString();
            dataGridView1.Rows[i].Cells[11].Value = dr[12].ToString();
        }

    }
    dr.Close();
    con.Close();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
finally
{
    con.Close();
}

How To Fix This

Thanks in advance for any recommendations or solutions.


Sumit Kesarwani

Total Post:378

Points:2694
Posted on    June-19-2013 8:45 AM

try this

cmd.CommandType = CommandType.StoredProcedure;

to execute stored procedure.

Don't want to miss updates? Please click the below button!

Follow MindStick