C#中怎么读取SQL数据库表中的数据后显示在一个TEXTBOX中?
2个回答
展开全部
private void GetDataByParmSqlCommand()
{
SqlConnection sqlc = new SqlConnection(DBUtility.SqlHelper.ConnectionStringLocalTransaction); //取连接字符串饼建立sqlconnection
try
{
sqlc.Open();
SqlCommand com = new SqlCommand("select * from c6 where usr_id = usr_id", sqlc);
SqlParameter parm = new SqlParameter();
parm.ParameterName = "@usr_id";
parm.Value = "01;
com.Parameters.Add(parm);
com.ExecuteNonQuery();
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(com);
sda.Fill(ds, "c6");
DataTable dt = ds.Tables[0];
textbox.Text ="用户代码:"+ dt.Rows[0]["usr_id"].ToString().Trim() +"用户名称:"+ dt.Rows[0]["usr_name"].ToString().Trim() ;
//这样组合一下就可以了,看你要显示哪些信息
}
catch (Exception ee)
{
MessageBox.Show(ee.Message, "");
}
finally
{
sqlc.Close();
}
}
{
SqlConnection sqlc = new SqlConnection(DBUtility.SqlHelper.ConnectionStringLocalTransaction); //取连接字符串饼建立sqlconnection
try
{
sqlc.Open();
SqlCommand com = new SqlCommand("select * from c6 where usr_id = usr_id", sqlc);
SqlParameter parm = new SqlParameter();
parm.ParameterName = "@usr_id";
parm.Value = "01;
com.Parameters.Add(parm);
com.ExecuteNonQuery();
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(com);
sda.Fill(ds, "c6");
DataTable dt = ds.Tables[0];
textbox.Text ="用户代码:"+ dt.Rows[0]["usr_id"].ToString().Trim() +"用户名称:"+ dt.Rows[0]["usr_name"].ToString().Trim() ;
//这样组合一下就可以了,看你要显示哪些信息
}
catch (Exception ee)
{
MessageBox.Show(ee.Message, "");
}
finally
{
sqlc.Close();
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询