62,268
社区成员
发帖
与我相关
我的任务
分享
foreach(DataRow dr in dt)
{
txtUserName.Text= dr["UserName"];
txtAge.Text= dr["age"];
txtsex.Text=dr["sex"];
}
SqlDataAdapter da = new SqlDataAdapter("select Id,UserName,Password,sex,age,Tel,Email from user where id="+id,conn)
DataTable dt = new DataTable();
da.Fill(dt);
txtUserName.Text= dt.Rows[0]["UserName"];
txtAge.Text= dt.Rows[0]["age"];
txtsex.Text=dt.Rows[0]["sex"];txtUserName.text= ds.Tables[0].Rows[0]["UserName"];
txtAge.text= ds.Tables[0].Rows[0]["age"];
txtsex.text=ds.Tables[0].Rows[0]["sex"];
public Page_Load(....)
{
if(!IsPostBack)
{
string strSql = "select Id,UserName,Password,sex,age,Tel,Email from user where id=1";
DataSet ds = Query(strSql);
if(ds!=null&&ds.Tables[0].Rows.Count>0)
{
txtUserName.text= ds.Tables[0].Rows[0]["UserName"];
txtAge.text= ds.Tables[0].Rows[0]["age"];
txtsex.text=ds.Tables[0].Rows[0]["sex"];
}
}
}
public static string connectionString = "..................";
/// <summary>
/// 执行查询语句,返回DataSet
/// </summary>
/// <param name="SQLString">查询语句</param>
/// <returns>DataSet</returns>
public static DataSet Query(string SQLString)
{
using (SqlConnection connection = new SqlConnection(connectionString))
{
DataSet ds = new DataSet();
try
{
connection.Open();
SqlDataAdapter command = new SqlDataAdapter(SQLString, connection);
command.Fill(ds, "ds");
}
catch (System.Data.SqlClient.SqlException ex)
{
throw new Exception(ex.Message);
}
return ds;
}
}