using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient;namespace combobox与TEXT关联 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public class hc { public DataTable mm(string sql) { DataTable dt = new DataTable(); string sqlconn = "data source=.;database=emgn_byang_sale;uid=sa;pwd=;"; SqlConnection ss = new SqlConnection(sqlconn); ss.Open(); SqlDataAdapter sd = new SqlDataAdapter(sql, ss); sd.Fill(dt); ss.Close(); return dt; } } private void Form1_Load(object sender, EventArgs e) { comboBox1.Items.Add("A"); comboBox1.Items.Add("B"); comboBox1.Items.Add("c");
} private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { hc da = new hc(); string sql = "select namec from t_sal_client where cst_originid='" + this.comboBox1.SelectedValue.ToString() + "'"; DataTable dt = da.mm(sql);
if (dt.Rows.Count == 0) { this.comboBox2.Text = "无"; } else { foreach (DataRow dr in dt.Rows)
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace combobox与TEXT关联
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public class hc
{
public DataTable mm(string sql)
{
DataTable dt = new DataTable();
string sqlconn = "data source=.;database=emgn_byang_sale;uid=sa;pwd=;";
SqlConnection ss = new SqlConnection(sqlconn);
ss.Open();
SqlDataAdapter sd = new SqlDataAdapter(sql, ss);
sd.Fill(dt);
ss.Close();
return dt;
}
} private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("A");
comboBox1.Items.Add("B");
comboBox1.Items.Add("c");
} private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
hc da = new hc();
string sql = "select namec from t_sal_client where cst_originid='" + this.comboBox1.SelectedValue.ToString() + "'";
DataTable dt = da.mm(sql);
if (dt.Rows.Count == 0)
{
this.comboBox2.Text = "无";
}
else
{
foreach (DataRow dr in dt.Rows)
this.comboBox2.Items.Add(dr.ItemArray[0].ToString());
}
} }
}
{
//根据comboBox1.SelectedValue的值在数据库中查询啊,把查询结果绑定到listview
}