0
我是新來的c#ASP.NET,我想檢查數據庫值與登錄部分的值插入,我做了一切正常,但爲什麼我仍然繼續得到的值是不正確的,而我輸入相同的值在我的數據庫中的一個......任何想法?我的行數爲dt繼續得到0 ...是否有什麼錯誤,當我添加參數?爲什麼結果返回0?
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Ng\Documents\Visual Studio 2015\Projects\Assignment6\Assignment6\App_Data\photoCompetition.mdf;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework");
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM [User] WHERE email='@useremail' and password='@password'", con);
cmd.Parameters.Add("@useremail", SqlDbType.Text).Value = emailtext.Text;
cmd.Parameters.Add("@password", SqlDbType.Text).Value = passwordtext.Text;
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
int i = cmd.ExecuteNonQuery();
con.Close();
if (dt.Rows.Count > 0)
{
Response.Redirect("Membermenu.aspx");
}
else
{
lblMsg.Text = "Your username and password is incorrect";
lblMsg.ForeColor = System.Drawing.Color.Red;
emailtext.Text = "";
passwordtext.Text = "";
}
}
我已經嘗試,但我得到這個錯誤數據類型varchar和文本在相等的操作符不兼容。 –
什麼是電子郵件和密碼列的數據類型?這是什麼數據庫? MS SQLServer? – Krishna
是varchar和數據庫是MSSQL服務器 –