Click here to Skip to main content
15,896,118 members

ASP.NET Insert Data - Dropdownlist Condition

Kuthay asked:

Open original thread
hello,

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;

C#
 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);
   conn.Open();
   cmd.Connection = conn;
   cmd.CommandText = strSQL;
   cmd.Parameters.Add
   cmd.Parameters.Add(new SqlParameter("@day", TextBox1.Text));
   cmd.Parameters.Add(new SqlParameter("@event", TextBox2.Text));
   int i = cmd.ExecuteNonQuery();
   conn.Close();
   if (i > 0)
      Response.Write("Data Inserted");
   else
      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.
Thanks.

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 ;

[ID],[NAME],[TYPE],[MON],[TUE],[WED],[THU],[FRI],[SAT],[SUN],[TOTAL],[DAY],[P1],[P2],[OVER].

Includes ;

ID NAME TYPE MON TUE....SUN TOTAL DAY P1 P2 OVER 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 day,p1,p2 and over values must be inserted into that chosen employee.

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

thanks.
Tags: C#, ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900