C#如何把从数据表中查询出来的sum结果在lable上显示出来
若以下回答无法解决问题,邀请你更新回答
展开全部
放在已个按钮事件下面,先说,如果有错,你要调试哈,要引用命名控件才可以哦
string ConnectionString=“Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=myproject;Data Source=.”
string sql="select * from 你的表名";
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
try
{
connection.Open();
SqlCommand command = new SqlCommand(stsql,connection);
SqlDataReader SDR = command.ExecuteReader();
if (SDR.Read())//只读第一条数据
{
lable1.Text=SDR[0].ToString();//SNO
lable2.Text=SDR[1].ToString();//SNAME
lable3.Text=SDR[2].ToString();//ssex
}
SDR.Close();
SDR.Dispose();
connection.Close();
connection.Dispose();
}
catch (Exception ex)
{
connection.Close();
connection.Dispose();
}
}
搞定
string ConnectionString=“Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=myproject;Data Source=.”
string sql="select * from 你的表名";
using (SqlConnection connection = new SqlConnection(ConnectionString))
{
try
{
connection.Open();
SqlCommand command = new SqlCommand(stsql,connection);
SqlDataReader SDR = command.ExecuteReader();
if (SDR.Read())//只读第一条数据
{
lable1.Text=SDR[0].ToString();//SNO
lable2.Text=SDR[1].ToString();//SNAME
lable3.Text=SDR[2].ToString();//ssex
}
SDR.Close();
SDR.Dispose();
connection.Close();
connection.Dispose();
}
catch (Exception ex)
{
connection.Close();
connection.Dispose();
}
}
搞定
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询