gpt4 book ai didi

c# - 我收到此错误 : An SqlParameter with ParameterName '@FirstName' is not contained by this SqlParameterCollection

转载 作者:太空宇宙 更新时间:2023-11-03 20:14:26 24 4
gpt4 key购买 nike

private void txtName_KeyDown(object sender, KeyEventArgs e)
{
SqlDataAdapter DA = new SqlDataAdapter("Search_Student",
DBConnection.GetConnection());
DA.SelectCommand.CommandType = CommandType.StoredProcedure;
DA.SelectCommand.Parameters["@FirstName"].Value = (txtName.Text).Trim();

DataTable DA1 = new DataTable();
DA.Fill(DA1);
dataGridView1.DataSource = DA1;
}

最佳答案

在给参数赋值之前必须先添加参数

SqlDataAdapter DA = new SqlDataAdapter("Search_Student",
DBConnection.GetConnection());
DA.SelectCommand.CommandType = CommandType.StoredProcedure;


SqlParameter param = new SqlParameter();
param.ParameterName = "@FirstName";
param.Value = txtName.Text;


DA.SelectCommand.Parameters.Add(param);

DataTable DA1 = new DataTable();
DA.Fill(DA1);
dataGridView1.DataSource = DA1;

关于c# - 我收到此错误 : An SqlParameter with ParameterName '@FirstName' is not contained by this SqlParameterCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17850855/

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