So I'm trying to retrieve the session variable (email) of the logged in user, and then use the variable in a SQL statement to retrieve the UserID of that user and place it in a read-only textbox. I can get the session variable and put that value in the textbox
but I also need the ID associated with the session(email).
After searching and trying 2 separate forum posts and analysing the breakpoints they both work to an extent but then I get the same error on both (System.Data.SqlClient.SqlException: 'The multi-part identifier "xxxxxx@gmail.com" could not be bound'. From
reading the error is mostly associated with problems joining tables but my blocks of code
don't do such a thing.
Here are the 2 separate blocks of code so if anyone could shed some light on why the error is appearing I would appreciate it hugely.
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString))
{
using (SqlCommand command = new SqlCommand("select UserID from Users where Email = " + Session["User"], connection))
{
connection.Open();
using (SqlDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
txtUserID.Text = reader[0].ToString();
}
}
}
}
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString);
SqlCommand cmd = new SqlCommand("select UserID from Users where Email = " + Session["User"]);
SqlDataAdapter ap = new SqlDataAdapter(cmd.CommandText, conn);
DataSet ds = new DataSet();
conn.Open();
ap.Fill(ds);
txtUserID.Text = ds.Tables[0].Rows.Count.ToString();
conn.Close();
According to your description and code, I think you have solved your issue, I hope you could mark your reply as answer. If not, please let us know.
Best Regards,
Eric Du
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
3 Points
16 Posts
The multi-part identifier could not be bound
Feb 06, 2018 09:55 PM|Markk25|LINK
So I'm trying to retrieve the session variable (email) of the logged in user, and then use the variable in a SQL statement to retrieve the UserID of that user and place it in a read-only textbox. I can get the session variable and put that value in the textbox but I also need the ID associated with the session(email).
After searching and trying 2 separate forum posts and analysing the breakpoints they both work to an extent but then I get the same error on both (System.Data.SqlClient.SqlException: 'The multi-part identifier "xxxxxx@gmail.com" could not be bound'. From reading the error is mostly associated with problems joining tables but my blocks of code don't do such a thing.
Here are the 2 separate blocks of code so if anyone could shed some light on why the error is appearing I would appreciate it hugely.
Regards,
Mark
Member
3 Points
16 Posts
Re: The multi-part identifier could not be bound
Feb 07, 2018 02:28 PM|Markk25|LINK
For anyone wondering the SQL statement should be like this,
Works for both variations
Contributor
6730 Points
2715 Posts
Re: The multi-part identifier could not be bound
Feb 08, 2018 02:29 AM|Eric Du|LINK
Hi Markk25,
According to your description and code, I think you have solved your issue, I hope you could mark your reply as answer. If not, please let us know.
Best Regards,
Eric Du
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.