private void Show() { DataTable dt = new DataTable(); SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM book_master_tbl", Con1.Connect()); adapter.Fill(dt); GridView1.AutoGenerateColumns = false; GridView1.DataSource = dt; GridView1.DataBind(); adapter = new SqlDataAdapter("SELECT author_name FROM author_master_tbl;", Con1.Connect()); dt = new DataTable(); adapter.Fill(dt); DropDownList_AuthorName.DataSource = dt; DropDownList_AuthorName.DataValueField = "author_name"; DropDownList_AuthorName.DataBind(); adapter = new SqlDataAdapter("SELECT publisher_name FROM publisher_master_tbl;", Con1.Connect()); dt = new DataTable(); adapter.Fill(dt); DropDownList_Publisher.DataSource = dt; DropDownList_Publisher.DataValueField = "publisher_name"; DropDownList_Publisher.DataBind(); }
void FillAuthorPublisherValues() { try { SqlConnection con = new SqlConnection(strcon); if (con.State == ConnectionState.Closed) { con.Open(); } SqlCommand cmd = new SqlCommand("Select author_name from dbo.author_master_tbl;", con); SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd); DataTable dataTable = new DataTable(); dataAdapter.Fill(dataTable); DropDownList_AuthorName.DataSource = dataTable; DropDownList_AuthorName.DataValueField = "author_name"; DropDownList_AuthorName.DataBind(); cmd = new SqlCommand("Select publisher_name from dbo.publisher_master_tbl;", con); dataAdapter = new SqlDataAdapter(cmd); dataTable = new DataTable(); dataAdapter.Fill(dataTable); DropDownList_Publisher.DataSource = dataTable; DropDownList_Publisher.DataValueField = "publisher_name"; DropDownList_Publisher.DataBind(); } catch (Exception ex) { } }