Click here to Skip to main content
16,003,345 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
this is my code

SqlConnection con= new SqlConnection("Data Source...)
protected void Page_Load(object sender, EventArgs e)
{
BindEmployeeDetails();
}


protected void BindEmployeeDetails()
{
con.Open();
SqlCommand cmd= new SqlCommand("select *from insertdetails",con);

SqlDataAdapter da = new SqlDataAdapter("select *from insertdetails", con);
DataSet ds= new DataSet();
da.Fill(ds,"insertdetails");
GridView1.DataSource = ds.Tables["insertdetails"];
GridView1.DataBind();
con.Close();
}

protected void Button1_Click(object sender, EventArgs e)
{
con.Open();

SqlCommand cmd1= new SqlCommand(" select * from insertdetails where username='"+TextBox1.Text+"'",con);
BindndEmployeeDetails();
con.Close();
}
Posted
Comments
Nandakishore G N 23-Jan-13 5:18am    
what are the errors paste it.?

change your query...for more better results..

C#
SqlCommand cmd1= new SqlCommand(" select * from insertdetails where username like '%"+TextBox1.Text+"%'",con);


and your code should be

C#
SqlConnection con= new SqlConnection("Data Source...");
protected void Page_Load(object sender, EventArgs e)
{
string command = "select * from insertdetails";
BindEmployeeDetails(command);
}
 

protected void BindEmployeeDetails(string command)
{
con.Open();
SqlCommand cmd= new SqlCommand(command);
 
SqlDataAdapter da = new SqlDataAdapter(cmd, con);
DataSet ds= new DataSet();
da.Fill(ds,"insertdetails");
GridView1.DataSource = ds.Tables["insertdetails"];
GridView1.DataBind();
con.Close();
}

protected void Button1_Click(object sender, EventArgs e)
{
string command = "select * from insertdetails where username like '%"+TextBox1.Text+"%'";
BindndEmployeeDetails(command);
}


C#

 
Share this answer
 
v5
Comments
mahesh202 23-Jan-13 5:46am    
declare cmd but it is not using na
Azziet 23-Jan-13 5:53am    
sorry!!! forgot to mention..answer is updated...now check the solution
mahesh202 23-Jan-13 5:54am    
BindEmployeeDetails does not exist in the correct content this is error
Azziet 23-Jan-13 5:57am    
what is the complete error ......?? make your method public from protected
First find the control from gridview event
 
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