将DropDownBox中的日期插入SQL列

时间:2014-05-29 10:06:41

标签: asp.net c#-4.0 sql-server-2014

所以继承我的代码:

protected void Button1_Click(object sender, EventArgs e)
    {
        string connectionString = "Data Source= *** ;Integrated Security=True;";
        System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectionString);
        conn.Open();
        string queryString = "INSERT INTO [Iliako_Sistima] (name,apostasi_apo_earth,arithmos_planiton,imerominia_entopismou) VALUES ('"+TextBoxName.Text+"','"+TextBoxEarthDistance.Text+"','"+TextBoxPlanets.Text+"','"+DropDownMonth.Text+"'/'"+DropDownDay.Text+"'/'"+DropDownYear.Text+"');";
        System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(queryString, conn);
        try
        {
            command.ExecuteNonQuery();
        }
        catch (Exception)
        {
            //Response.Redirect("Error.aspx", true);
        }
        conn.Close();
        //Response.Redirect("NewSolar.aspx", false);
    }

我想在“imerominia_entopismou”列中插入3个DropDownBoxes(DropDownDay,DropDownMonth,DropDownYear)中选择的日期

问题是这段代码('“+ DropDownMonth.Text +”'/'“+ DropDownDay.Text +”'/'“+ DropDownYear.Text +”')不会这样做,因为他得到一个sql错误

我怎样才能成功?

1 个答案:

答案 0 :(得分:1)

尝试在“/".

之间没有单引号'