m0_73948435 2023-06-23 21:38 采纳率: 0%
浏览 9

VS实现销售系统查询

img



```c#
private void button5_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == "" && textBox3.Text == "")
            {
                MessageBox.Show("对不起,请输入价格范围");
                textBox2.Focus();
                return;
            }
                        
            if (textBox2.Text != "" && textBox3.Text == "")
                strSql = "Select Price * From BasicInformationAboutCars where Price  >=  textBox2.text";
            else if(textBox2.Text== "" && textBox3.Text != "")
                strSql = "Select Price * From BasicInformationAboutCars where Price<= + textBox3.Text + ";
            else
                strSql = "Select Price * From BasicInformationAboutCars where Price>= + textBox2.Text + and Price<= + textBox3.Text + ";
            
            exeSQL(strSql);
        }

问题:在textbox2、3中输入数字范围,查询结果不显示?报错:至少一个参数没有被指定值怎么回事?

  • 写回答

3条回答 默认 最新

  • 易只轻松熊 2023-06-23 21:55
    关注

    根据您提供的代码,报错信息"至少一个参数没有被指定值"是由于您在SQL语句中没有正确地引用文本框的值。在SQL语句中,您需要使用字符串拼接的方式将文本框中的值与SQL语句连接起来。

    以下是修改后的代码示例:

    private void button5_Click(object sender, EventArgs e)
    {
        if (textBox2.Text == "" && textBox3.Text == "")
        {
            MessageBox.Show("对不起,请输入价格范围");
            textBox2.Focus();
            return;
        }
    
        if (textBox2.Text != "" && textBox3.Text == "")
            strSql = "Select Price * From BasicInformationAboutCars where Price >= " + textBox2.Text;
        else if (textBox2.Text == "" && textBox3.Text != "")
            strSql = "Select Price * From BasicInformationAboutCars where Price <= " + textBox3.Text;
        else
            strSql = "Select Price * From BasicInformationAboutCars where Price >= " + textBox2.Text + " and Price <= " + textBox3.Text;
    
        exeSQL(strSql);
    }
    

    在修改后的代码中,使用了字符串拼接的方式将文本框的值与SQL语句连接起来,以正确地传递参数值给SQL查询语句。

    评论

报告相同问题?

问题事件

  • 修改了问题 6月23日
  • 创建了问题 6月23日

悬赏问题

  • ¥15 用matlab或python实现多个表格合并单元格
  • ¥15 gojs 点击按钮node的position位置进行改变,再次点击回到原来的位置
  • ¥15 计算决策面并仿真附上结果
  • ¥20 halcon 图像拼接
  • ¥15 webstorm上开发的vue3+vite5+typeScript打包时报错
  • ¥15 vue使用gojs,需求在link中的虚线上添加方向箭头
  • ¥15 CSS通配符清除内外边距为什么可以覆盖默认样式?
  • ¥15 SPSS分类模型实训题步骤
  • ¥100 求ASMedia ASM1184e & ASM1187e 芯片datasheet/规格书
  • ¥15 求解决扩散模型代码问题