ASP.NET插入数据 - 下拉列表条件 [英] ASP.NET Insert Data - Dropdownlist Condition

查看:69
本文介绍了ASP.NET插入数据 - 下拉列表条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我有asp.net项目有下拉列表。我需要根据下拉列表条件将数据插入我的数据库。



例如;在我的项目中,我将选择员工,我将从我的文本框中插入一些值,点击底部的按钮后,我需要将更改插入从我的下拉列表中选择员工的数据库。



这是按钮点击代码;



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;

 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");
}





等待你的帮助。我环顾四周但看不到这样的例子或想法。

我需要你的帮助。

谢谢。



编辑1

几乎找到答案。谢谢你的回答。但这是问题所在。这个命令在我的表中添加了新的行,我需要插入一个现有的行。



这里有一些让你头脑清醒的东西;



i有惩罚表,其中包括columuns;



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



包含;



ID姓名类型MON TUE ....太阳总天P1 P2天后



------------------------------------------- ------------------------



1迈克250 350 ..... 0 900 - - - - 22-06-2012



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


正如你从这里看到我的朋友,我将从我的datetimepickers中选择日期,我将从我的下拉列表中选择员工,我将把值输入文本框,之后我将点击完成按钮。



当天,p1,p2及以上值必须插入所选员工。



请等待你的回答,我需要它太糟糕了..



谢谢。



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.

推荐答案





首先你能否清楚ny怀疑,



1.你要插入数据的员工表abd既是理智的表,也是不同的表

2.您是否要为该员工插入数据或更新数据。

2.如果两个表格不同,请提供您想要的表格结构输入数据。



所以我觉得这很简单就没那么难了。



谢谢和问候

Suman Zalodiya
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


这篇关于ASP.NET插入数据 - 下拉列表条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆