有个表单,里面有3选择出生年月的DropDownList,ID分别为year,month,data,有个问题是我如何取得这3个值并将其放入sql server 2000数据库(数据库里面我设置为DataTime类型)!

解决方案 »

  1.   

    select cast(year+'.'+month+'.'+data as datetime)
      

  2.   

    拼成日期格式然后转成DateTime放进去
      

  3.   

    string DateTemp = YYYY + DD + MM;
    DateTime DateInsert = Convert.ToDateTime(DateTemp);
    把DateInsert插入到数据库就好了;
    如果是用DataRow 
    DataRow AddRow = New DataRow();
    AddRow["时间列"] = DateInsert;如果是用SQL 
    "Insert(时间列)values('" + DateTemp +"')";
      

  4.   

    string ymd=DropDownList1.SelectValue+"-"+DropDownList2.SelectValue+"-"DropDownList3.SelectValue;
    DateTime dt=DateTime.Parse(ymd);
      

  5.   

    不好意思!打错了
    string ymd=DropDownList1.SelectValue+"-"+DropDownList2.SelectValue+"-"+DropDownList3.SelectValue;
    DateTime dt=DateTime.Parse(ymd);
      

  6.   


    在每个DropDownList(year,month,data)的OnSelectedIndexChanged事件中写如下类似代码if(year.SelectedIndex>-1)  //判断是否有选择
    {
      string yr=year.SelectedItem.Value //把选择的值存入一个变量中
    }。。
    。。
    再用insert数据库的时候,cast(year+'.'+month+'.'+data as datetime)。插入数据库中就OK了!