在sql数据库中使用asp.net保存下拉列表值 [英] save dropdown list value using asp.net in sql database

查看:61
本文介绍了在sql数据库中使用asp.net保存下拉列表值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hI,



我有以下下拉菜单



< asp:DropDownList ID =DropDownList2 runat =server>

< asp:ListItem>请选择

< asp:ListItem> A

< asp :ListItem> B

< asp:ListItem> C

< asp:ListItem> D





我想保存值,就像当我选择a或b或c或d中的任何一个值时,如果我选择并单击保存按钮,这些值中的任何一个都会保存到sql server中,请指导我怎么办

解决方案

你选择一个下拉项,你需要保存在SQL表中的项值,对吧......?



这首先创建SQL表,并在页面中根据您获取所选值的项目选择项目,然后根据您保存的值保存你的数据库。


SqlConnection cn = new SqlConnection(cnstr);

SqlCommand cmd = new SqlCommand(insert into Employe values(''+ DropDownList1.SelectedValue +''),cn);

cn.Open();

cmd.ExecuteNonQuery();

cn.Close();



一旦你可以尝试选择的价值,可以尝试一次这样的帮助......其他明智的代替选择的项目。


hI,

I have following dropdown

<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem>Please Select
<asp:ListItem>A
<asp:ListItem>B
<asp:ListItem>C
<asp:ListItem>D


I want to save the value like when i select a or b or c or d any one of the value if i select and on click of the save button the any of these value get saved into sql server , pls guide me how can i do so

解决方案

you select one dropdown item, that item value you need to save in SQL table , right ...?

for this first of all you create SQL table, and in page wise you select the item whatever you want based upon the item you fetch selected value, then that value you save in your DB.


SqlConnection cn = new SqlConnection(cnstr);
SqlCommand cmd = new SqlCommand("insert into Employe values(''" + DropDownList1.SelectedValue + "'')", cn);
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();

May be this help you try it once.....other wise in the place of "selected item" once you can try "selected value".


这篇关于在sql数据库中使用asp.net保存下拉列表值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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