Click here to Skip to main content
12,949,826 members (77,298 online)
Rate this:
 
Please Sign up or sign in to vote.
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
protected void Button1_Click(object sender, EventArgs e)
  {
      string s = TextBox1.Text;
      objcus.name(s);
  }


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




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 5-Feb-13 21:04pm
Comments
Krunal Rohit 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 ?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You are missing quotes on your varchar field type.
int add = s.DMLQuery("select Customer_Name from Tbl_Customer where Email_Id ='" + emailid + "'" + );
  Permalink  
Comments
_Amy 6-Feb-13 3:43am
   
Exactly. +5!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

yeah You're Missing Quotes-
the query would be like-

 
"select Customer_Name from Tbl_Customer where Email_Id ='" + emailid + "'"
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

i think sqlcommond is missing ,
Please mention command text in sqlcmd = new SqlCommand("");
  Permalink  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,489
CHill60 3,380
Maciej Los 2,913
Jochen Arndt 1,935
ppolymorphe 1,820


Advertise | Privacy | Mobile
Web02 | 2.8.170524.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100