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 TPosted Sep 29, 2015, 7:13 AM
<%@ 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();
Raja TPosted Sep 30, 2015, 1:39 AM
Rajveer SinghPosted Sep 30, 2015, 1:17 AM
Raja TPosted Sep 30, 2015, 12:46 AM
Rajveer SinghPosted Sep 30, 2015, 12:05 AM
Raja TPosted Sep 29, 2015, 12:10 PM
Rajveer SinghPosted Sep 29, 2015, 9:06 AM
Raja TPosted Sep 29, 2015, 9:00 AM
Raja TPosted Sep 29, 2015, 8:56 AM
Raja TPosted Sep 29, 2015, 8:46 AM
Raja TPosted Sep 29, 2015, 8:41 AM
Rajveer SinghPosted Sep 29, 2015, 8:39 AM
Raja TPosted Sep 29, 2015, 8:31 AM
Rajveer SinghPosted Sep 29, 2015, 8:29 AM
Raja TPosted Sep 29, 2015, 8:07 AM
Raja TPosted Sep 29, 2015, 8:03 AM
Raja TPosted Sep 29, 2015, 7:41 AM
Rajveer SinghPosted Sep 29, 2015, 7:37 AM
Raja TPosted Sep 29, 2015, 7:05 AM
Rajveer SinghPosted Sep 29, 2015, 7:04 AM
Raja TPosted Sep 29, 2015, 7:02 AM
Rajveer SinghPosted Sep 29, 2015, 6:56 AM
Raja TPosted Sep 29, 2015, 6:51 AM
Rajveer SinghPosted Sep 29, 2015, 6:38 AM
<%: Title %>.
Manage Pets.
Choose a Breed:
Raja TPosted Sep 29, 2015, 6:35 AM
Rajveer SinghPosted Sep 29, 2015, 6:10 AM
Rajveer SinghPosted Sep 29, 2015, 6:09 AM
Rajveer SinghPosted Sep 29, 2015, 6:04 AM
Raja TPosted Sep 28, 2015, 10:34 AM
Raja TPosted Sep 28, 2015, 10:32 AM
Rajveer SinghPosted Sep 28, 2015, 10:20 AM
Raja TPosted Sep 28, 2015, 9:53 AM
Supreeth JPosted Sep 28, 2015, 9:51 AM
Raja TPosted Sep 28, 2015, 9:50 AM
Rajveer SinghPosted Sep 28, 2015, 9:45 AM
Rajveer SinghPosted Sep 28, 2015, 9:30 AM
Supreeth JPosted Sep 28, 2015, 9:28 AM
Rajveer SinghPosted Sep 28, 2015, 9:28 AM
Rajveer SinghPosted Sep 28, 2015, 9:26 AM
Raja TPosted Sep 28, 2015, 6:33 AM
Raja TPosted Sep 28, 2015, 6:31 AM
Supreeth JPosted Sep 28, 2015, 6:24 AM