代码如下:
private void txbid_TextChanged(object sender, System.EventArgs e)
{
string sqlstr;
string sqlco= ConfigurationSettings.AppSettings["strCon"];
SqlConnection sqlcon=new SqlConnection(sqlco);
sqlstr="select 姓名,单位 from 读者表 where 条码=@kahao";
SqlDataAdapter da = new SqlDataAdapter(sqlstr,sqlcon);
da.SelectCommand.Parameters.Add(new SqlParameter("@kahao",SqlDbType.VarChar,20));
da.SelectCommand.Parameters["@kahao"].Value=txbid.Text;
DataSet ds = new DataSet();
da.Fill(ds,"读者表");
lbxm.Text=??????(这里应该把表中的姓名列的内容显示出来)
lbxb.Text=???????? (这里应该把表中的单位列的内容显示出来)
问号那里的语句该怎么写,我用的是:
lbxm.Text=ds.Tables[0].Columns[0].ToString();
lbxb.Text=ds.Tables[0].Columns[1].ToString();
结果运行结果显示的是字段名,而没有把表中的数据读出来,
private void txbid_TextChanged(object sender, System.EventArgs e)
{
string sqlstr;
string sqlco= ConfigurationSettings.AppSettings["strCon"];
SqlConnection sqlcon=new SqlConnection(sqlco);
sqlstr="select 姓名,单位 from 读者表 where 条码=@kahao";
SqlDataAdapter da = new SqlDataAdapter(sqlstr,sqlcon);
da.SelectCommand.Parameters.Add(new SqlParameter("@kahao",SqlDbType.VarChar,20));
da.SelectCommand.Parameters["@kahao"].Value=txbid.Text;
DataSet ds = new DataSet();
da.Fill(ds,"读者表");
lbxm.Text=??????(这里应该把表中的姓名列的内容显示出来)
lbxb.Text=???????? (这里应该把表中的单位列的内容显示出来)
问号那里的语句该怎么写,我用的是:
lbxm.Text=ds.Tables[0].Columns[0].ToString();
lbxb.Text=ds.Tables[0].Columns[1].ToString();
结果运行结果显示的是字段名,而没有把表中的数据读出来,
{
lbxm.Text=ds.Tables[0].Rows[0][0].ToString();
lbxb.Text=ds.Tables[0].Rows[0][1].ToString();
}
for(int i=0;i<ds.Tables[0].Rows.Count){
string xm+=ds.Tables[0].Rows[0][0].ToString()+",";
string xb+=ds.Tables[0].Rows[0][1].ToString()+","; lbxm.Text=Substring(0,xm.lenth-1);
lbxb.Text=Substring(0,xb.lenth-1);
}