读书人

连接数据查询两个字段分别放入两个不同

发布时间: 2012-12-16 12:02:32 作者: rapoo

求助连接数据查询两个字段分别放入两个不同该如何处理
由于初学所以运用上比较生疏请求各位指导 在此万分感谢
[最优解释]
SqlConnection con = db.qq();
string sql = "select id,foodprice from tb_food where foodname='" + db.foodname + "'";
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
SqlDataReader dr= cmd.ExecuteReader();
if (dr.Read())
{
textbox1.Text = dr[0];
textbox2.Text = dr[1];
}
[其他解释]

引用:
db.foodname=treeView1.SelectedNode.Text;
textBox2.Text = db.foodname;
textBox2.ReadOnly = true;
if (treeView1.SelectedNode.Level > 1)
{
……

你把 textBox1.Text = dr[0].ToString();
textBox3.Text = dr[1].ToString();
改成
textBox1.Text = dr["id"].ToString();
textBox3.Text = dr["foodprice "].ToString();
还是没有数据的话,你调试看看
[其他解释]
自己顶个 怎么没人回答呢
[其他解释]
收藏 求助连接数据查询两个字段分别放入两个不同该如何处理 [、
什么意思?
两个不同。。
是什么意思

[其他解释]
描述不清楚,都不知道你想做什么?
[其他解释]
引用:
描述不清楚,都不知道你想做什么?
db.foodname=treeView1.SelectedNode.Text;
textBox2.Text = db.foodname;
textBox2.ReadOnly = true;
if (treeView1.SelectedNode.Level > 1)
{
SqlConnection con = db.qq();
con.Open();
string sql="select id,foodprice from tb_food where foodname='"+db.foodname+"'";


我需要把查询出来的 id,foodprice输出在两个文本框控件里面;我不知道用什么语句了;
[其他解释]

引用:
收藏 求助连接数据查询两个字段分别放入两个不同该如何处理 [、
什么意思?
两个不同。。
是什么意思

db.foodname=treeView1.SelectedNode.Text;
textBox2.Text = db.foodname;
textBox2.ReadOnly = true;
if (treeView1.SelectedNode.Level > 1)
{
SqlConnection con = db.qq();
con.Open();
string sql="select id,foodprice from tb_food where foodname='"+db.foodname+"'";
我需要把查询出来的 id,foodprice输出在两个文本框控件里面;我不知道用什么语句了;
[其他解释]
楼上正解!!
[其他解释]
引用:
SqlConnection con = db.qq();
string sql = "select id,foodprice from tb_food where foodname='" + db.foodname + "'";
SqlCommand cmd = new SqlCommand(sql, con);
……
我点击以后还是没法显示 也不报错;
[其他解释]

db.foodname=treeView1.SelectedNode.Text;
textBox2.Text = db.foodname;
textBox2.ReadOnly = true;
if (treeView1.SelectedNode.Level > 1)
{
SqlConnection con = db.qq();
con.Open();
string sql="select id,foodprice from tb_food where foodname='"+db.foodname+"'";
SqlCommand com = new SqlCommand(sql, con);
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
textBox1.Text = dr[0].ToString();
textBox3.Text = dr[1].ToString();


}
还是没法显示
[其他解释]

引用:
引用:db.foodname=treeView1.SelectedNode.Text;
textBox2.Text = db.foodname;
textBox2.ReadOnly = true;
if (treeView1.SelectedNode.Level ……
db.foodname=treeView1.SelectedNode.Text;
textBox2.Text = db.foodname;
textBox2.ReadOnly = true;
if (treeView1.SelectedNode.Level > 1)
{
SqlConnection con = db.qq();
con.Open();
string sql="select id,foodprice from tb_food where foodname='"+db.foodname+"'";
SqlCommand com = new SqlCommand(sql, con);
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
textBox1.Text = dr["id"].ToString();
textBox3.Text = dr["foodprice"].ToString();
}
}
[其他解释]
还是不行 点击以后还是不显示在控件上
[其他解释]
  public DataSet GetwbDate()
{
DataSet ds = new DataSet();
cmd = new OleDbCommand("select * from tiezineirong where Tname = '楼主是个好人'", conn);
da = new OleDbDataAdapter(cmd);
da.Fill(ds, "tiezineirong");
return ds;
}



 public  OleDbDataReader reader(string sql)
{
OleDbDataReader reader = null;


string command = "";
cmd = new OleDbCommand(command, conn);

cmd.CommandText = sql;
reader = cmd.ExecuteReader();
return reader;

}



读取
 OleDbDataReader reader = new kyo().reader(sql);

if (reader.Read())
{
label1.Visible = true;
string a = "学号:";



a += reader["Sno"].ToString(); //Mark reader读取方法1
a += "\n姓名:";
a += reader.GetString(1); // Mark reader 读取方法二
a += "\n性别:";
a += reader.GetString(2);
a += "\n年龄:";
a += reader.GetValue(3);
a += "\n院系:";
a += reader.GetString(4);
a += "\n年级:";
a += reader.GetString(5);
a += "级\n专业:";
a += reader.GetString(6);
a += "\n";
// a += reader.GetValue (7);
// a += "\n";
name = reader["Sname"].ToString();
label1.Text = a;



// textBox1.Text = a;
//MessageBox.Show(a);
}
else
{
MessageBox.Show("无该数据");
}




 string sql;
sql = string.Format("select * from student where Sno = '{0}'", this.id);
#region // DateGridView 使用方法
DataSet ds = new dbc.conndbc().login_DD(sql);
if (ds.Tables[0].Rows.Count > 0)
{
dataGridView1.DataSource = ds.Tables[0];
}

[其他解释]
点级它的子节点然后显示在右边的文本框内
[其他解释]
在自己顶个求正解
[其他解释]
在自己顶一个 求大神

读书人网 >C#

热点推荐