am using asp.net 3.5(c#) + sql server 200 DB,

doing this GIVES me an error ,
Error:The multi-part identifier "email@yahoo.com" could not be bound
why ???

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class advertisementSubmission : System.Web.UI.Page
    protected String EmplyrSession;

    protected void Page_Load(object sender, EventArgs e)

        EmplyrSession = (String) Session["UserEmail"];
        String conString = "Data Source=COSANOSTRA;Initial Catalog=Waleed_orsfinal;Integrated Security=True";
        //Sql Connection
        SqlConnection con = new SqlConnection(conString);
        //Sql Command
        String query = "select userid from tblUser where email=" + EmplyrSession;
        SqlCommand com = new SqlCommand(query, con);
        catch (Exception ex)
            Response.Write("Error:" + ex.Message);


        //Sql DataAdapter
        //SqlDataAdapter da = new SqlDataAdapter(com);
        ////Sql DataSet
        //DataSet ds = new DataSet();
        //da.Fill(ds, "tblJobAdv");

        ////Filling DetailsView
        //DetailsViewAdvSubmission.DataSource = ds;

        int jbid = int.Parse( Request.QueryString["jbid"]);
4 Years
Discussion Span
Last Post by JorgeM

I suspect it is because of the '@' symbol. I beleive that this is a special character since asp.net uses this character for the parameter names.


@jorGem: i removed @ but nw it gives me another error,
ERROR: invalid column emailyahoo.com though its been saved in db but no luck ,


Ok that is because you need to wrap the string with apostrophes. Try this.

select userid from tblUser where email = '" + EmplyrSession + "'";

= (apostrophe)(quote) + EmplyrSession + (quote)(apostrophe)(quote);

If you wrap it with an apostrophe you may be able to Include the @ symbol. Try it.


@jorGem: one thing more, just for my own knowledge that why does it need so many astrophes , quotes ?
i never got it clear that how many and where to use atrophes , quotes etc ?


In SQL, when you use the WHERE clause, if you do enclose the argument with apostophes, SQL will interpret that as a field.

So, for example...Hunain is seen as a field in the table.

Select empID from employee where empName = Hunain

In this example, Hunain is taken as a string value.

Select empID from employee where empName = 'Hunain'

In the example you have above...

String query = "select userid from tblUser where email='" + EmplyrSession + "'";

Before you close the first quote, you slip in the first apostrophe so its part of the statement. Then open the quote again after the variable so you can continue the statement, then add the closing apostrophe, then a final quote to close the entire string that you are assigning to the variable "query".

Votes + Comments
thanks alot Jorgem, u r a true genius
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.