Helloo i would like to find out how can i display my Tables in my Database using the Drop Down List Box.
When display, i have two tables(Dog and Cat) so if i choose Dog then i will be able to add data into the Dog table.. Same thing if choose Cat then ill be able to add data into the Cat table. Please help me as im stuck here.
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 3:13 AM EDT
<%@ Page Title="Pets" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Pets.aspx.cs" Inherits="WebApplication2.Pets" %>
<%: Title %>.
Manage Pets.
Choose a Breed:
DropDownList1" runat="server" Height="20px" Width="250px">
--------------------------------
In Code behind page
protected void Button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Project\WebApplication2\App_Data\Database1.mdf;Integrated Security=True");
if (DropDownList1.Text == "Dog") //Choose Dog
{
SqlCommand cmd = new SqlCommand("Insert into dog(Id, Breed, Name, Age, Gender, Weight, Date) Values (@Id, @Breed, @Name, @Age, @Gender, @Weight, @Date)", con);
cmd.Parameters.AddWithValue("@Id", tb7.Text);
cmd.Parameters.AddWithValue("@Breed", tb1.Text);
cmd.Parameters.AddWithValue("@Name", tb2.Text);
cmd.Parameters.AddWithValue("@Age", tb3.Text);
cmd.Parameters.AddWithValue("@Gender", tb4.Text);
cmd.Parameters.AddWithValue("@Weight", tb5.Text);
cmd.Parameters.AddWithValue("@Date", tb6.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
else if (DropDownList1.Text == "Cat") //Choose Cat
{
SqlCommand cmd = new SqlCommand("Insert into cat(Id, Breed, Name, Age, Gender, Weight, Date) Values (@Id, @Breed, @Name, @Age, @Gender, @Weight, @Date)", con);
cmd.Parameters.AddWithValue("@Id", tb7.Text);
cmd.Parameters.AddWithValue("@Breed", tb1.Text);
cmd.Parameters.AddWithValue("@Name", tb2.Text);
cmd.Parameters.AddWithValue("@Age", tb3.Text);
cmd.Parameters.AddWithValue("@Gender", tb4.Text);
cmd.Parameters.AddWithValue("@Weight", tb5.Text);
cmd.Parameters.AddWithValue("@Date", tb6.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Supreeth JRank #2,205 · 639 reputationPosted Sep 28, 2015, 2:24 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 28, 2015, 2:31 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 28, 2015, 2:33 AM EDT
Rajveer Singh69 reputationPosted Sep 28, 2015, 5:26 AM EDT
Rajveer Singh69 reputationPosted Sep 28, 2015, 5:28 AM EDT
Supreeth JRank #2,205 · 639 reputationPosted Sep 28, 2015, 5:28 AM EDT
Rajveer Singh69 reputationPosted Sep 28, 2015, 5:30 AM EDT
Rajveer Singh69 reputationPosted Sep 28, 2015, 5:45 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 28, 2015, 5:50 AM EDT
Supreeth JRank #2,205 · 639 reputationPosted Sep 28, 2015, 5:51 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 28, 2015, 5:53 AM EDT
Rajveer Singh69 reputationPosted Sep 28, 2015, 6:20 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 28, 2015, 6:32 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 28, 2015, 6:34 AM EDT
Rajveer Singh69 reputationPosted Sep 29, 2015, 2:04 AM EDT
Rajveer Singh69 reputationPosted Sep 29, 2015, 2:09 AM EDT
Rajveer Singh69 reputationPosted Sep 29, 2015, 2:10 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 2:35 AM EDT
Rajveer Singh69 reputationPosted Sep 29, 2015, 2:38 AM EDT
<%: Title %>.
Manage Pets.
Choose a Breed:
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 2:51 AM EDT
Rajveer Singh69 reputationPosted Sep 29, 2015, 2:56 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 3:02 AM EDT
Rajveer Singh69 reputationPosted Sep 29, 2015, 3:04 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 3:05 AM EDT
Rajveer Singh69 reputationPosted Sep 29, 2015, 3:37 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 3:41 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 4:03 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 4:07 AM EDT
Rajveer Singh69 reputationPosted Sep 29, 2015, 4:29 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 4:31 AM EDT
Rajveer Singh69 reputationPosted Sep 29, 2015, 4:39 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 4:41 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 4:46 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 4:56 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 5:00 AM EDT
Rajveer Singh69 reputationPosted Sep 29, 2015, 5:06 AM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 8:10 AM EDT
Rajveer Singh69 reputationPosted Sep 29, 2015, 8:05 PM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 8:46 PM EDT
Rajveer Singh69 reputationPosted Sep 29, 2015, 9:17 PM EDT
Raja TRank #685 · 3.5K reputationPosted Sep 29, 2015, 9:39 PM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts