使用sql将下拉列表值存储在数据库中 [英] storing drop down list values in database using sql

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

问题描述

我有三个下拉列表,如日期,山高,年份,我从数据库中获得了该列表值.从用户那里获得了这些值之后,我想发送到数据库中

我的代码
< asp:DropDownList ID =日期" runat =服务器"></asp:DropDownList>< asp:DropDownList ID ="mounth" runat ="server"><//asp:DropDownList>< asp:DropDownList ID ="year" runat ="server"></asp:DropDownList>

.cs代码

I had three dropdown list like date,mounth,year I getting this list values from database.After getting this valuesfrom user i want send to database

my code
<asp:DropDownList ID="date" runat="server"></asp:DropDownList><asp:DropDownList ID="mounth" runat="server"></asp:DropDownList><asp:DropDownList ID="year" runat="server"></asp:DropDownList>

.cs code

sqlcon.Open();
        adap = new SqlDataAdapter("select date from dof", sqlcon);
        ds = new DataSet();
        adap.Fill(ds);
        date.DataSource = ds;
        date.DataTextField = "date";
        date.DataBind();
        sqlcon.Close();
        sqlcon.Open();
        adap = new SqlDataAdapter("select mounth from dof", sqlcon);
        ds = new DataSet();
        adap.Fill(ds);
        mounth.DataSource = ds;
        mounth.DataTextField = "mounth";
        mounth.DataBind();
        sqlcon.Close();
        sqlcon.Open();
        adap = new SqlDataAdapter("select year from dof", sqlcon);
        ds = new DataSet();
        adap.Fill(ds);
        year.DataSource = ds;
        year.DataTextField = "year";
        year.DataBind();
        sqlcon.Close();


如何将此值插入数据库


how to insert this values into data base

推荐答案

您的问题尚不清楚.你有什么要求意味着您要分别保存所有三个值还是将其保存为日期.

Your question is not clear. What is your requirement. Means do u want to save all the three values separtely or as the date.

DateTime SelectedDate = new DateTime(Convert.ToInt32(year.SelectedItem.Value), Convert.ToInt32(month.SelectedItem.Value), Convert.ToInt32(date.SelectedItem.Value));


但是你可以喜欢


But you can like that


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

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