---
title: "how to pass Sql parameter"  
description: "how to pass Sql parameter"  
author: "Anonymous User"  
published: 2013-06-19  
updated: 2013-06-19  
canonical: https://www.mindstick.com/forum/1218/how-to-pass-sql-parameter  
category: "ado.net"  
tags: ["ado.net"]  
reading_time: 2 minutes  

---

# how to pass Sql parameter

Hi [Developers](https://www.mindstick.com/articles/12875/blunders-you-must-avoid-while-hiring-java-developers-to-get-the-best-fulfilling-your-needs), \
I have created [stored procedure](https://www.mindstick.com/articles/803/using-stored-procedure-in-asp-dot-net) that expects one [parameter](https://www.mindstick.com/blog/450/parameter-class-in-c-sharp) '@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](https://yourviews.mindstick.com/view/80763/donald-trump-ki-jeet-fix-hai) This\
Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams) for any recommendations or solutions.

## Replies

### Reply by Sumit Kesarwani

try this\
**cmd.CommandType = CommandType.StoredProcedure;**\
to execute [stored](https://www.mindstick.com/forum/157561/what-is-the-stored-procedure-create-a-procedure-to-find-the-record-by-stu_id-from-the-student-table) [procedure](https://www.mindstick.com/forum/32/stored-procedure-return-datatype).


---

Original Source: https://www.mindstick.com/forum/1218/how-to-pass-sql-parameter

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
