Search values from database in c# sql
i am developing a windows application. i have a data grid view. How can i search value from a single row and display them in a text box??
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vinodh NarayananPosted Feb 2, 2015, 5:36 AM
protected void btnsearch_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["DBTSSMConnectionString"].ConnectionString);
// string str = "Data Source=.;Initial Catalog=DBTSSM;Integrated Security=True";
//SqlConnection con = new SqlConnection(str);
string student = txtSearch.Text == "" ? "''" : txtSearch.Text;
string acad = txtSearch.Text == "" ? "''" :txtSearch.Text;
string sect = txtSearch.Text == "" ? "''" : txtSearch.Text;
string sect1 = txtSearch.Text == "" ? "''" : txtSearch.Text;
string roll = txtSearch.Text == "" ? "''" : txtSearch.Text;
string route = txtSearch.Text== "" ? "''" : txtSearch.Text;
string s1 = "''";
string query = "select *from tbl_studentss where Student_Name like '" + student + '%' + "' or Student_Acadyear like '" + acad + '%' + "' or Student_Class like '" + sect + '%' + "' or Student_Section like '" + sect1 + '%' + "' or Student_Rollno like '" + roll + '%' + "' or Route_Details like '" + route + '%' + "'";
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
DataTable dts = new DataTable();
da.Fill(dts);
insert.DataSourceID = null;
insert.DataSource = dts;
insert.DataBind();
}
insert is a gridname......
mark if accepted answer...