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"];
        Response.Write(EmplyrSession);
        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);
        try
        {
            con.Open();
            com.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            Response.Write("Error:" + ex.Message);

        }
        finally
        {
            con.Close();
        }

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

        ////Filling DetailsView
        //DetailsViewAdvSubmission.DataSource = ds;
        //DetailsViewAdvSubmission.DataBind();

        int jbid = int.Parse( Request.QueryString["jbid"]);
        Response.Write(jbid);
    }
}

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 ,
HOW ?

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.

wowwww jorGem, hatts off man, u did it, it worked , Thanks alot man

@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".

commented: thanks alot Jorgem, u r a true genius +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.