Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to retrive data

i created one table customer with email_id nvarchar(50) as p.k,cust_name nvarchar(50),cust_address nvarchar(50)

now in form i want to retrive customer name depending upon email address

i performed following:

here textbox1 is email id entered by user
C#
protected void Button1_Click(object sender, EventArgs e)
  {
      string s = TextBox1.Text;
      objcus.name(s);
  }


C#
public void name(string emailid)
      {
          int add = s.DMLQuery("select Customer_Name from Tbl_Customer where Email_Id =" + emailid);
      }




C#
public int DMLQuery(string SqlCommandText)
       {

           Sqlconn = new SqlConnection(StrSqlconnection);
           Sqlconn.Open();
           sqlcmd = new SqlCommand();
           sqlcmd.CommandText = SqlCommandText;
           sqlcmd.Connection = Sqlconn;
           int i = sqlcmd.ExecuteNonQuery();
           return i;
       }


i am getting error on int i = sqlcmd.ExecuteNonQuery(); as " The multi-part identifier "shivani@ossagho.com" could not be bound."

pls teell what i missed

regards
Posted
Comments
[no name] 6-Feb-13 3:06am    
What you are actually tryin to do ?
Ankur\m/ 6-Feb-13 3:08am    
I guess it's a quote. Can you debug and post what's saved in sqlcmd.CommandText ?

You are missing quotes on your varchar field type.
int add = s.DMLQuery("select Customer_Name from Tbl_Customer where Email_Id ='" + emailid + "'" + );
 
Share this answer
 
Comments
_Amy 6-Feb-13 3:43am    
Exactly. +5!
C#
public void name(string emailid)
      {
          int add = s.DMLQuery("select Customer_Name from Tbl_Customer where Email_Id = '" + emailid + "'");
      }


I agree to Ankur as well. It is a quote issue. I prefer you use Parametrized Queries[^] for escaping the quotes and avoiding SQL injections.

Good luck,
OI
 
Share this answer
 
yeah You're Missing Quotes-
the query would be like-

C#
"select Customer_Name from Tbl_Customer where Email_Id ='" + emailid + "'"
 
Share this answer
 
i think sqlcommond is missing ,
Please mention command text in sqlcmd = new SqlCommand("");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900