css - 当我知道该值不为空时,Asp.net 参数显示为 null

标签 css asp.net excel gridview

当传递一个我知道存在的值时,出现以下错误。

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/

相关文章:

excel - 如何动态地将单元格值放入Excel中多页的文本框中?

arrays - 范围联合无序

html - 为什么我的导航栏没有完全向左延伸?

html - 相对于具有响应内容的固定 div 定位 div

不遵守 CSS Flexbox 最大宽度

.net - 流利的 NHibernate : multiple one-to-many relationships between the same entities

asp.net - : rendering server tags at runtime in asp.网络有可能吗?

css - 在 Vue 组件中正确使用 SASS

包含文件之间的 Javascript 事件委托(delegate)

Excel 退出和宏运行 : 'Code execution has been interupted'