gpt4 book ai didi

c# - Sql参数的传递方式

转载 作者:太空宇宙 更新时间:2023-11-03 18:34:58 25 4
gpt4 key购买 nike

此错误将出现在我的代码中 程序或函数“gridalldata”需要参数“@order_no”,但未提供该参数。我正在向如下过程发送参数

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();
}

如何解决这个问题

最佳答案

使用cmd.CommandType = CommandType.StoredProcedure; 执行存储过程。

关于c# - Sql参数的传递方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16773449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com