jorax 2023-04-09 23:25 采纳率: 80%
浏览 34
已结题

winform根据两组条件查询结果

winform根据两组条件查询产品价格
选择产地combox1,输入型号textbox1,点击botton1,在textbox2中输出产品价格
数据表名为:价格表
请问要怎么写?

img

img

  • 写回答

1条回答 默认 最新

  • threenewbee 2023-04-09 23:33
    关注
    string connectionString = "Data Source=.;Initial Catalog=数据库名;Integrated Security=True"; //这里替换成你的连接字符串
    string sql = string.Format("select 价格 from 价格表 where 产地 = '{0}' and 型号 = '{1}'", comboBox1.Text, textBox1.Text);
    
    using (SqlConnection connection = new SqlConnection(connectionString))
    {
        connection.Open();
    
        using (SqlCommand command = new SqlCommand(sql, connection))
        {
            object result = command.ExecuteScalar();
            if (result != null)
            {
                textBox2.Text = result.ToString();
            }
        }
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 4月10日
  • 已采纳回答 4月10日
  • 创建了问题 4月9日

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度