关于comboBox的问题---------------
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e){
DataSet ds = new DataSet();
SqlDataAdapter sar = new SqlDataAdapter();
ds.Clear();
sar.Fill(ds, "RoomType");
this.comboBoxd.DataSource = ds;
this.comboBoxd.ValueMember = "TypeId";
this.comboBoxd.DisplayMember = "TypeName";
}
我想从数据库里读出列表
但显示不出来,是哪里错的了啊?
我刚学.NET不久,有没有Framework比较精通的啊,能加我QQ或者MSN教教我?放心我不会一直打扰你的 --------------------编程问答-------------------- SqlDataAdapter 没有和 SqlConnection 建立连接呢。 --------------------编程问答-------------------- DataSet ds = new DataSet();
SqlDataAdapter sar = new SqlDataAdapter();
ds.Clear();
sar.Fill(ds, "RoomType");
没有查询出来
public static DataSet ReturnDataSet(string cmdtext)
{
cmd = new SqlCommand(cmdtext, GetConn());
//类型
cmd.CommandType =CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
try
{
da.Fill(ds);
}
catch (Exception err)
{
throw err;
}
finally
{
if (cn.State != ConnectionState.Closed)
{
cn.Close();
}
}
return ds;
}
传SQL语句进去 --------------------编程问答-------------------- 1.sqlConncetion 没有
2.SQL 语句呢?
--------------------编程问答-------------------- 数据根本就没取到,肯定没有的,
参考2楼的方法,再去试试吧 --------------------编程问答--------------------
sqlconnection没有。
sql语句也没看见。。 --------------------编程问答--------------------
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)--------------------编程问答-------------------- 问题一、你在Combox的下拉改变事件中进行数据绑定???
{
DataSet ds = new DataSet();
string str="";//数据库的位置,连接字符串,这个你自己设,我不知道你的数据库
SqlConnection con=new SqlConnection(str);
con.Open();//try catch我省了,你应该加上
string sql="";//查询语句,你自己写,我不知道你的数据库里的个表
SqlDataAdapter sar = new SqlDataAdapter(con,sql);
ds.Clear();
sar.Fill(ds, "RoomType");
con.Close();//关闭
this.comboBoxd.DataSource = ds;
this.comboBoxd.ValueMember = "TypeId";
this.comboBoxd.DisplayMember = "TypeName";
}
问题二、你的SQL语句呢?空的适配器你去填充数据集,怎么会有数据???
--------------------编程问答-------------------- 不能在comboBox1_SelectedIndexChanged里绑定。本来就没有下拉项,何来的选中变更。
private void Form_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;uid=sa;pwd=sa;Database=数据库名称;");
DataSet ds = new DataSet();
string strSQL = "select * from 你的表名";
SqlDataAdapter sar = new SqlDataAdapter(strSQL,con);
sar.Fill(ds, "RoomType");
this.comboBoxd.DataSource = ds.Tables["RoomType"];
this.comboBoxd.ValueMember = "TypeId";
this.comboBoxd.DisplayMember = "TypeName";
}
--------------------编程问答-------------------- 2楼牛啊。 --------------------编程问答-------------------- 没有连接 没有sql语句.. --------------------编程问答-------------------- 顶二楼
补充:.NET技术 , .NET Framework