我得到這個錯誤:出錯轉換字符串的SqlConnection
Cannot implicitly convert type string to System.Data.SqlClient.SqlConnection
這裏是我的C#代碼。
protected void Button1_Click(object sender, EventArgs e)
{
//login button
SqlConnection sqlConn = "Your Conncetion String"; //The error is here
sqlConn.Open();
SqlCommand sqlComm = new SqlCommand();
sqlComm.CommandText = String.Format("select * from users where [email protected] and [email protected]");
sqlComm.Parameters.AddWithValue("@userName", TextBox1.Text.Trim());
sqlComm.Parameters.AddWithValue("@password", TextBox2.Text.Trim());
sqlComm.CommandType = CommandType.Text;
sqlComm.Connection = sqlConn;
SqlDataReader sqlRead = sqlComm.ExecuteReader();
if (sqlRead.Read())
{
Session["username"] = sqlRead["username"];
}
// SqlRead.Close();
//sqlConn1.Close();
Response.Redirect("Default.aspx");
}
有人可以解釋這個錯誤意味着什麼以及如何解決它?
那麼你需要證明你的代碼! – meda
有關您編寫的代碼問題的問題必須描述具體問題,並在問題本身中包含有效的代碼以再現問題。 –
***顯示代碼***(vtc) – abelenky