을 sqlsyntax합니다 :문자열 내가 가진 문자열
string theUserId = Session["UserID"].ToString();
을하지만
{
if (Session["UserID"] != null)
{
string theUserId = Session["UserID"].ToString();
Label1.Text = Convert.ToString(theUserId);
OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver}; Server=localhost; Database=gymwebsite; User=x; Password=x;");
cn.Open();
OdbcCommand cmd = new OdbcCommand("SELECT User.FirstName, User.SecondName, User.Aboutme, User.DOB, Pictures.picturepath FROM User LEFT JOIN Pictures ON User.UserID = Pictures.UserID WHERE [email protected]"), cn);
cmd.Parameters.AddWithValue("@UserID", theUserId);
OdbcDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
Name.Text = String.Format("{0} {1}", reader.GetString(0), reader.GetString(1));
Aboutme.Text = String.Format("{0}", reader.GetString(2));
Age.Text = String.Format("{0}", reader.GetString(3));
Image1.ImageUrl = String.Format("{0}", reader.GetString(4));
}
}
}
}
User.UserID=1
가 어떻게 바꿀 것이 sqlsnytax에 문자열을 추가하는 방법을 잘 모릅니다 무언가에
@Brandon에는 요구 사항에 따라 올바른 답이 있습니다. 그러나 몇 가지 유의해야합니다. 첫째, "theUserId"는 실행 전에 소생 될 필요가 있습니다. 그것이 의미하는 바에는 SQL 인젝션이 그곳에 쓰여져 있습니다. 둘째, 나는 당신이 이것을 지나가고 있다는 것이 확실하지 않지만, 누군가 그것을 찢어야 할 것처럼 보입니다. codereview.stackexchange.com – NotMe
@ uhhardy에서 코드 일부를 게시 할 수 있습니다. WraithNath는 기본적으로 모든 잡음이없는 동일한 대답을 가지고 있습니다. 나는 내 것을 제거하고 대신 자신을 upvoted. – Brandon
고맙다 Brandon, 나는 따라갈 것이다. – ukhardy