怎么选到comboBox1更新数值啊

.Net技术 码拜 9年前 (2016-06-06) 919次浏览
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace eye4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            string sql = "select * from pinpai";
            DataSet ds = DBHelper.getset(sql);
            comboBox1.DataSource = ds.Tables[0];
            comboBox1.DisplayMember = "NAME";
           
        }
        public string sql { get; set; }
        private void query()
        {
            sql = "select * from text1";
            DataTable dt1 = DBHelper.getset(sql).Tables[0];
            sql = "select * from text2";
            DataTable dt2 = DBHelper.getset(sql).Tables[0];
            sql = "select pinpai.NAME,AA_Inventory.name,ST_CurrentStock.baseQuantity,"" as a,"" as b  " +
                " from pinpai left join AA_Inventory on pinpai.id = AA_Inventory.productInfo " +
                " left join ST_CurrentStock on ST_CurrentStock.idinventory = AA_Inventory.id where  pinpai.NAME="" + this.comboBox1.SelectedItem.ToString() + """;
            DataTable dt3 = DBHelper.getset(sql).Tables[0];
            foreach (DataRow dr in dt3.Rows)
            {
                int iindex1 = dr["name1"].ToString().IndexOf("-", 0);
                int iindex2 = dr["name1"].ToString().IndexOf("-", iindex1 + 1);
                string a = dr["name1"].ToString().Substring(iindex1+1, iindex2-iindex1-1 );
                string b = dr["name1"].ToString().Substring(iindex2+1, dr["name1"].ToString().Trim().Length - iindex2-1);
                dr["a"] = Convert.ToDecimal (a);
                dr["b"] = Convert.ToDecimal (b);
               // string a =dr["name1"].ToString ().Trim ().Substring ( dr["name1"].ToString().IndexOf("-", 0);
            }
            DataTable dt = new DataTable();
            dt.Columns.Add("球镜柱镜", typeof(System.String));
            foreach (DataRow dr in dt1.Rows)
            {
                dt.Columns.Add(dr["value"].ToString().Trim(), typeof(System.Double ));
            }
            foreach (DataRow dr in dt2.Rows)
            {
                DataRow dradd = dt.NewRow();
                dradd["球镜柱镜"] = dr["value"];
                dt.Rows.Add(dradd);
            }
            this.dataGridView1.DataSource = dt;
            foreach (DataRow dr in dt3.Rows)
            {
                foreach (DataRow dr1 in dt.Rows)
                {
                    if (dr["a"].ToString().Trim() == dr1["球镜柱镜"].ToString().Trim())
                    {
                        dr1[dr["b"].ToString ().Trim ()] = dr["baseQuantity"];
                    }
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            query();
        }
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
        }
    }
}

要显示出效果怎么选到comboBox1更新数值啊怎样选择条件以后更新0.0

解决方案

20

你是要选中comboBox,依据comboBox选中的值获取相应的查询结果?
假如是这样在comboBox1_SelectedIndexChanged事件中调用query()方法不就可以了?comboBox1_SelectedIndexChanged事件你不是都写了么?

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明怎么选到comboBox1更新数值啊
喜欢 (0)
[1034331897@qq.com]
分享 (0)