在我的項目中,我需要該用戶將看到位於同一城市的用戶的車庫。不能看到我希望看到的gridview數據
我創建的用戶表,其中包括 - Id,UserName,Password,Email,CarModel,Year,City,
,另一個表是GarageUsers
包括 - Id,UserName,Password,Email,Address,City,GarageName
。
在Configure Data Source
我insertes此代碼:
SELECT GargeUsers.GarageName, GargeUsers.Address,GargeUsers.City,GargeUsers.Email
FROM GargeUsers
INNER JOIN GarageuserCategory ON GargeUsers.Id = GarageuserCategory.UserId
I
WHERE (GarageuserCategory.CategoryId = 1) AND (GargeUsers.City LIKE Users.City)
(該GarageUserCategory是顯示類別 - 其確定在當前的數據忽略)。
在這段代碼中,我看到了所有的車庫。
我添加用戶登錄時保存用戶城市的會話。 但我不能在gridview中看到我想要的。我需要知道如何平等會話(USerCity)車庫城。
protected void LogIn_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) from Users where UserName= '" + UserName.Text + "'";
SqlCommand com = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
conn.Close();
if (temp == 1)
{
conn.Open();
string checkPasswordQuery = "select Password from Users where UserName= '" + UserName.Text + "'";
SqlCommand passComm = new SqlCommand(checkPasswordQuery, conn);
string password = passComm.ExecuteScalar().ToString().Replace(" ", "");
string UserCityQuery = "select City from Users where UserName= '" + UserName.Text + "'";
SqlCommand cityComm = new SqlCommand(UserCityQuery, conn);
string UserCity = cityComm.ExecuteScalar().ToString().Replace(" ", "");
if (password == Password.Text)
{
Session["UserCity"] = UserCity;
Session["New"] = UserName.Text;
Response.Write("Password is correct");
Response.Redirect("HomePage.aspx");
}
else
{
Response.Write("Password is not correct");
}
}
else
{
Response.Write("User Name is not correct");
}
}
}
}
選擇城市你能提供樣本數據和預期結果嗎? – dotnetom
我必須知道一些,也許你可以幫助我。我必須插入英文數據還是無所謂? – Elishay
嘗試創建[SQL FIDDLE](http://sqlfiddle.com/#!9/7358e/4),以便我們可以看到數據。查詢看起來不錯。 –