当传递一个我知道存在的值时,出现以下错误。
System.Data.OleDb.OleDbException: 'No value given for one or more required parameters.'
我正在填充具有单个输出的 GridView 。然后我使用它来填充新的 GridView 。
OleDbConnection conn1 = new OleDbConnection();
string path1 = Server.MapPath("Price_List.xlsx");
String connString1 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties='Excel 12.0;IMEX=1;'";
conn1.ConnectionString = connString1;
conn1.Open();
OleDbCommand cmd1 = new OleDbCommand("select * from [Sheet1$] Where [Meter Type] =" + GridView1.Rows[0].Cells[0].Text, conn1);
OleDbDataReader rd1 = cmd1.ExecuteReader();
GridView2.DataSource = rd1;
GridView2.DataBind();
我知道密码
GridView1.Rows[0].Cells[0].Text
显示 GridView 1 中的单例,因为我已经在文本框中对其进行了测试,并显示了我要显示的内容。
我看不出哪里错了。
最佳答案
假设 [Meter Type] 是一个字符串字段,您在 sql 中缺少单引号:
OleDbCommand cmd1 = new OleDbCommand("select * from [Sheet1$] Where [Meter Type] = '"+ GridView1.Rows[0].Cells[0].Text + "'", conn1);
关于css - 当我知道该值不为空时,Asp.net 参数显示为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53853694/