0
我想從數據表中獲取usert_id值並將其分配給c#中的會話變量。但我無法獲得我的代碼中的user_id。我怎樣才能做到這一點?如何從c#中的數據表中獲取user_id
try
{
conn.Open();
MySqlCommand cmd = new MySqlCommand("Select * from students where user_name='" + loginname.Text + "' and user_password ='" + password.Text + "'", conn);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
ShowMessage(dt.Row['.user_id.']);
Session["user_id"] = "bar";
Response.Redirect("dashboard.aspx");
}
else
{
Response.Write("<script>alert('Please enter valid Username and Password')</script>");
}
}
嗨你得到一種錯誤的東西? – Max
http://stackoverflow.com/questions/13816490/get-cell-value-from-a-datatable-in-c-sharp –
應該用雙引號(「)不是一個單引號(') – MickyD