Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0
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 22:04pm
Comments
Krunal Rohit at 6-Feb-13 3:06am
   
What you are actually tryin to do ?
Ankur\m/ at 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 at 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
0 OriginalGriff 428
1 Maciej Los 249
2 BillWoodruff 199
3 /\jmot 180
4 Suraj Sahoo | Coding Passion 150
0 OriginalGriff 8,484
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,639
3 Maciej Los 5,159
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 6 Feb 2013
Copyright © CodeProject, 1999-2014
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