Click here to Skip to main content
13,512,710 members
Rate this:
Please Sign up or sign in to vote.
See more:

i have 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 = "Insert INTO info (day,event) Values (@day,@event)";
   string bag_str = WebConfigurationManager.ConnectionStrings["asgdb01ConnectionString"].ConnectionString;
   conn = new SqlConnection(bag_str);
   cmd.Connection = conn;
   cmd.CommandText = strSQL;
   cmd.Parameters.Add(new SqlParameter("@day", TextBox1.Text));
   cmd.Parameters.Add(new SqlParameter("@event", TextBox2.Text));
   int i = cmd.ExecuteNonQuery();
   if (i > 0)
      Response.Write("Data Inserted");
      Response.Write("Try Again");

Waiting your helps. I looked around too much but couldnt see the example or idea like that.
Please i need your helps.

edit 1
The answer is nearly found.Thanks for your answer. But here is the problem. This commands adds new rows into my table, i need to insert an existing row.

Here something to make your mind clear;

i have penalties table which includes that columuns ;


Includes ;



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 day,p1,p2 and over values must be inserted into that chosen employee.

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

Posted 31-Dec-12 2:51am
Updated 1-Jan-13 4:43am
Zafar Sultan 31-Dec-12 8:56am
Can you make your question more clear. You want to insert data in the database selected from the list or in a database for the selected employee from the list? Give a more understandable example.
Sandeep Mewara 31-Dec-12 16:34pm
OP has posted an update as an answer:

Zafar Sultan, yes my friend, i want to insert data in to the database with my button click event on .cs side of my project but i will choose the employee name from my dropdownlist. I need to insert data into that selected employee.

Here is something to make clear on your mind;

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

(label1) DAY : ______________ (TEXTBOX1)

(label2) EVENT : ______________ (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.
Did you understand what i mean my friend ?


1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Hi ,

First can you clear ny doubt,

1. Employee table abd in which you want to insert the data are both the sane table or different table
2. Do you want to insert the data for that employee or update the data.
2. If both the table are different then please give the structure of the table in which you want to enter the data.

So i think it's very simple no so tough.

Thanks and regards
Suman Zalodiya
Kuthay 1-Jan-13 10:45am
thanks for your comments my friend, can you look my this topic, its more clear there;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.180417.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100