我在下面尝试过编码但没有发生任何事情。所有文本框都是空白的。
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=USER-PC;Initial Catalog=1GCAttendanceManagementSystem;Integrated Security=True");
DataTable dt = new DataTable();
con.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("select * from Employee where EmpUsername='" + Session["id"] + "'", con);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
txtCode.Text = (myReader["EmployeeId"].ToString());
txtUsername.Text = (myReader["EmpUsername"].ToString());
txtPass.Text = (myReader["EmpPassword"].ToString());
txtEmail.Text = (myReader["EmpEmail"].ToString());
txtFirstname.Text = (myReader["EmpFirstName"].ToString());
txtLastname.Text = (myReader["EmpLastName"].ToString());
txtGender.Text = (myReader["EmpGender"].ToString());
txtContact.Text = (myReader["EmpContact"].ToString());
txtAddress.Text = (myReader["EmpAddress"].ToString());
txtDept.Text = (myReader["EmpDept"].ToString());
}
con.Close();
}
答案 0 :(得分:1)
你能尝试下面的事吗。
为了更好的实施,我做了以下几点修改。
如果您收到任何错误,请更新您的问题。
protected void Page_Load(object sender, EventArgs e)
{
using (SqlConnection con = new SqlConnection("Data Source=USER-PC;Initial Catalog=1GCAttendanceManagementSystem;Integrated Security=True"))
{
con.Open();
SqlDataReader myReader = null;
var salaryParam = new SqlParameter("EmpUsername", SqlDbType.VarChar);
salaryParam.Value = Session["id"];
SqlCommand myCommand = new SqlCommand("select TOP 1 * from Employee where EmpUsername='@EmpUsername'", con);
myCommand.Parameters.Add(salaryParam);
myReader = myCommand.ExecuteReader();
if (myReader.Read())
{
txtCode.Text = (myReader["EmployeeId"].ToString());
txtUsername.Text = (myReader["EmpUsername"].ToString());
txtPass.Text = (myReader["EmpPassword"].ToString());
txtEmail.Text = (myReader["EmpEmail"].ToString());
txtFirstname.Text = (myReader["EmpFirstName"].ToString());
txtLastname.Text = (myReader["EmpLastName"].ToString());
txtGender.Text = (myReader["EmpGender"].ToString());
txtContact.Text = (myReader["EmpContact"].ToString());
txtAddress.Text = (myReader["EmpAddress"].ToString());
txtDept.Text = (myReader["EmpDept"].ToString());
}
}
}
答案 1 :(得分:1)
如果你的连接字符串,查询和检索字段名称是正确的,请在页面加载中尝试此代码...它将起作用
func recursionUpload() {
.. some other code
var s3 = new AWS.S3({apiVersion: '2006-03-01', region: 'us-west-2'});
var params = {
Bucket: 'bucket',
Key: 'example2.txt',
Body: 'Uploaded text using the promise-based method!'
};
var putObjectPromise = s3.putObject(params).promise();
putObjectPromise.then(function(data) {
console.log('Success');
//Upload next image
recursionUpload()
}).catch(function(err) {
console.log(err);
});
}