Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
string str = "select * from Employee_Details where Employee_Name='" + txt_serch_by.Text + "'";
SqlCommand objgcmd = new SqlCommand(str, ObjCon);
SqlDataAdapter sda = new SqlDataAdapter(objgcmd);
DataTable dt1 = new DataTable();

sda.Fill(dt1);






from this code am getting a error message like-----The name 'txt_serch_by' does not exist in the current contex-------
how to overcome this eror
Posted

its seems that Textbox "txt_serch_by" is not added on form correctly or it is not present.
Please check whether is present or else please provide the design code.
 
Share this answer
 
Comments
geo thomas 30-Apr-13 3:35am    
no..txt_serch_by" is not added on form correctly...


#endregion

private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox cmb_serch;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.LinkLabel linkLabel1;
private System.Windows.Forms.Label lbl_serch_by;
private System.Windows.Forms.TextBox txt_serch_by;
Kushal.patil121 30-Apr-13 5:08am    
I would recommend you to drag and drop text box from Toolbox to Form.
It will create all necessary properties in design .....
and after that give ID as txt_serch_by2 and use that in your query .....
Please try it, by storing "txt_serch_by" with one variable in string format and read from that variable.
 
Share this answer
 
Comments
geo thomas 30-Apr-13 3:38am    
no...its not working
VipulAgrawal 30-Apr-13 4:40am    
Are you adding the text box in gridview?????....Then search control by FindControl() function...It will solve the problem.....
Kushal.patil121 30-Apr-13 5:07am    
Vipul its seems that he is working on Windows project not web Project.... ;)
geo thomas 30-Apr-13 5:17am    
thanku....its solved nw...
It seems that your txt_serch_by not properly registered to designer page.
remove the textbox and add it again.
 
Share this answer
 
Comments
geo thomas 30-Apr-13 6:33am    
i was tryin to access the text bob name in a form to a class...
TrushnaK 30-Apr-13 6:35am    
Then what?

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