asp.net把数据查询的值存到dataset
我想查询数据库Guest表内的8个字段到dataset里.并且能够重里面一个一个的取到label上"selectName,Sex,Card,RoomID,Type,Mob...
我想查询数据库Guest表内的8个字段到dataset里.并且能够重里面一个一个的取到label上
"select Name,Sex,Card,RoomID,Type,Mobile,Money,IsAddBed from Guest where Users"
请给出详细的代码以作参考!谢谢..
1楼的第一个方法看不懂. 展开
"select Name,Sex,Card,RoomID,Type,Mobile,Money,IsAddBed from Guest where Users"
请给出详细的代码以作参考!谢谢..
1楼的第一个方法看不懂. 展开
展开全部
用这个
public static SqlConnection SQLConn()
{
string ConnStr = ConfigurationManager.ConnectionStrings["gngsdb_heatingConn"].ConnectionString;
ConnStr = ConfigurationManager.ConnectionStrings["AGWebHeating"].ConnectionString;
ConnStr = ConfigurationManager.ConnectionStrings["AGHeating"].ConnectionString;
//ConnStr = ConfigurationManager.ConnectionStrings["AGHeatinga"].ConnectionString;
try
{
return new SqlConnection(ConnStr);
}
catch
{
return null;
}
}
//获取查询语句的结果 DataSet
public static DataSet QuerySQL(string SQLTxt,SqlConnection Conn)
{
try
{
DataSet DS = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(SQLTxt, Conn);
da.Fill(DS);
Conn.Close();
return DS;
}
catch
{
return null;
}
}
string SQLStr = 'select Name,Sex,Card,RoomID,Type,Mobile,Money,IsAddBed from Guest where Users'
DataSet DS = QuerySQL(SQLStr,SQLConn());
Label1.Text = DS.Tables[0].Rows[0]["Name"].ToString();
public static SqlConnection SQLConn()
{
string ConnStr = ConfigurationManager.ConnectionStrings["gngsdb_heatingConn"].ConnectionString;
ConnStr = ConfigurationManager.ConnectionStrings["AGWebHeating"].ConnectionString;
ConnStr = ConfigurationManager.ConnectionStrings["AGHeating"].ConnectionString;
//ConnStr = ConfigurationManager.ConnectionStrings["AGHeatinga"].ConnectionString;
try
{
return new SqlConnection(ConnStr);
}
catch
{
return null;
}
}
//获取查询语句的结果 DataSet
public static DataSet QuerySQL(string SQLTxt,SqlConnection Conn)
{
try
{
DataSet DS = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(SQLTxt, Conn);
da.Fill(DS);
Conn.Close();
return DS;
}
catch
{
return null;
}
}
string SQLStr = 'select Name,Sex,Card,RoomID,Type,Mobile,Money,IsAddBed from Guest where Users'
DataSet DS = QuerySQL(SQLStr,SQLConn());
Label1.Text = DS.Tables[0].Rows[0]["Name"].ToString();
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询