Answered by:
Select the data from database

Question
-
I need visual studio c# coding my doubt is how to select data from sqlserver below the example model
My form is this
i need to select from database when i select author in combobox that related data display in next combobox i.e Bookname
when i select author that related bookname display in combo box my database model is below the picture
for example i select author name like "Balaguruswamy" i want display "Bookname" related from balaguruswamy i.e. java,C++,C these bookname will display in Combobox then i will select anyone display whole data
please help i need c# , sqlserver coding...
karthik
Monday, July 28, 2014 2:17 AM
Answers
-
The C# version is at the top of the page, but it lost the screen designs that the VB version has kept.
- Proposed as answer by Ioana Vasilescu Monday, July 28, 2014 6:48 AM
- Marked as answer by Anne Jing Sunday, August 3, 2014 11:48 AM
Monday, July 28, 2014 4:53 AM -
Hi Karthik,
Hope this will be helpful. Just change the SQL query to set the fetch the data based on the drop down box "Authors" selected value like ,
//Assuming your Author dropdown is ddlAuthor string value = ddlAuthor.SelectedValue; //Creating a new SQL command SqlCommand command = new SqlCommand("select Bookname from tablename where Author = @author",connection); //Adding the author parameter command.Parameters.Add("@author",sqlDbType.Varchar32); //Assigning the author parameter value command.Parameters["@author"].Value = value; //Creating a SQLReader SqlDataReader drBooks = command.ExecuteReader(); //Assigning the fetched values to Books drop down ddlBooks.DataSource = drBooks; ddlBooks.DataValueField = "Bookname"; ddlBooks.DataTextField = "Bookname"; ddlBooks.DataBind();
Regards, Ram If you find the answer as helpful, Please vote as helpful.
- Marked as answer by Anne Jing Sunday, August 3, 2014 11:47 AM
Monday, July 28, 2014 8:56 AM
All replies
-
The C# version is at the top of the page, but it lost the screen designs that the VB version has kept.
- Proposed as answer by Ioana Vasilescu Monday, July 28, 2014 6:48 AM
- Marked as answer by Anne Jing Sunday, August 3, 2014 11:48 AM
Monday, July 28, 2014 4:53 AM -
Hi Karthik,
Hope this will be helpful. Just change the SQL query to set the fetch the data based on the drop down box "Authors" selected value like ,
//Assuming your Author dropdown is ddlAuthor string value = ddlAuthor.SelectedValue; //Creating a new SQL command SqlCommand command = new SqlCommand("select Bookname from tablename where Author = @author",connection); //Adding the author parameter command.Parameters.Add("@author",sqlDbType.Varchar32); //Assigning the author parameter value command.Parameters["@author"].Value = value; //Creating a SQLReader SqlDataReader drBooks = command.ExecuteReader(); //Assigning the fetched values to Books drop down ddlBooks.DataSource = drBooks; ddlBooks.DataValueField = "Bookname"; ddlBooks.DataTextField = "Bookname"; ddlBooks.DataBind();
Regards, Ram If you find the answer as helpful, Please vote as helpful.
- Marked as answer by Anne Jing Sunday, August 3, 2014 11:47 AM
Monday, July 28, 2014 8:56 AM -
thank u ram
karthik
Friday, August 1, 2014 12:45 PM -
Saturday, August 2, 2014 1:49 AM