Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9065465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:30:33+00:00 2026-06-16T16:30:33+00:00

i have asp.net project which has dropdownlist. i need to insert data into my

  • 0

i have asp.net project which has dropdownlist. i need to insert data into my database according to dropdownlist condition.

For example; in my project, i will choose the employee and i will insert the some values from my textboxes and after clicking button on the bottom, i need to insert the changes into database that selected employee from my dropdownlist.

Here is the button click codes;

protected void Button2_Click(object sender, EventArgs e)
{
    SqlConnection conn;
    SqlCommand cmd = new SqlCommand();
    string strSQL = "UPDATE info (empid,day1,day2,date1) Values (@empid,@day1,@day2,@date1)";
    string bag_str = WebConfigurationManager.ConnectionStrings["asgdb01ConnectionString"].ConnectionString;
    conn = new SqlConnection(bag_str);
    conn.Open();
    cmd.Connection = conn;
    cmd.CommandText = strSQL;
    cmd.Parameters.Add(new SqlParameter("@day1", Int32.Parse(DropDownList1.SelectedItem.Value)));
    cmd.Parameters.Add(new SqlParameter("@day1", Int32.Parse(TextBox1.Text)));
    cmd.Parameters.Add(new SqlParameter("@day2", Int32.Parse(TextBox2.Text)));
    cmd.Parameters.Add(new SqlParameter("@date1", CalendarExtender1.SelectedDate));
    int i = cmd.ExecuteNonQuery();
    conn.Close();
    if (i > 0)
        Response.Write("Data Inserted");
    else
        Response.Write("Try Again");

}

Here is something to make clear on your mind;

|Dropdownlist1| (i will click here and names will appear you know.)

-Mike

-John

-Susan

-Kevin

(label1) DAY1 : ______ (TEXTBOX1)

(label2) DAY2: ______ (TEXTBOX2)

|FINISH| (button1)

You see from here, i will click dropdownlist and i will choose the employee. After i will enter the values and i will click on FINISH button and data will be inserted into that selected employee.

Here is the key question; how can i tell the button_click event; you will insert these data’s into selected employees table which i have chosen the employee from dropdownlist. okay ?

I tried to make sample of the table here;

ID NAME TYPE MON TUE …. SUN TOTAL DAY1 DAY2 DATE


1 mike out 250 350 ….. 0 900 – – 22-06-2012

2 john in 350 150 …. 100 1100 – – 28-06-2012

As you see from here my friend, i will choose the dates from my datetimepickers, i will choose the employee from my dropdownlist and i will enter the values into textboxes and after that i will click finish button.

the day1,day2 values must be inserted into that chosen employee.

waiting your answer please, i need it too badly..

thanks.

Waiting your helps with four eye.
Thanks.

Did you understand what i mean my friends ? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:30:34+00:00Added an answer on June 16, 2026 at 4:30 pm

    If you did not set the dropdownlist’s SelectedValue, you should set it to be the employee’s id.

    Then, modify your function to also take into account the value in the dropdownlist like this:

    protected void Button2_Click(object sender, EventArgs e)
    {
        SqlConnection conn;
        SqlCommand cmd = new SqlCommand();
        string strSQL = "Insert INTO info (id, day1,day2) Values (@id, @day1,@day2)";
        string bag_str = WebConfigurationManager.ConnectionStrings["asgdb01ConnectionString"].ConnectionString;
        conn = new SqlConnection(bag_str);
        conn.Open();
        cmd.Connection = conn;
        cmd.CommandText = strSQL;
        cmd.Parameters.Add(new SqlParameter("@id", Int32.Parse(DropDownList1.SelectedValue)));
        cmd.Parameters.Add(new SqlParameter("@day1", TextBox1.Text));
        cmd.Parameters.Add(new SqlParameter("@day2", TextBox2.Text));
    
        int i = cmd.ExecuteNonQuery();
        conn.Close();
        ....
    }
    

    Notice the change is using the SelectedValue property of the DropdownList to find the correct Id

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET project which has already some custom fields in it's web.config
I have a master page in my asp.net MVC project, which has code like
I have an ASP.NET project which is a front-end to a database. In addition
In my ASP.NET Web-form Project I have an Event which Export Data ( List<Profit>
We have a large ASP.NET project which has 100s of BLL classes. In our
I have a form in an ASP.NET MVC project which has a select drop
I have asp.net project which has got GridViews, Buttons, Navigators etc... I have 10-15
I have a custom ValidationAttribute in my ASP.NET MVC3 project which has two conditions
I have an ASP.NET MVC 2 project in which I've created a data transfer
I have one of a aspx page in my asp.net project which has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.