Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 将下拉框中的日期插入SQL列_Asp.net_C# 4.0_Sql Server 2014 - Fatal编程技术网

Asp.net 将下拉框中的日期插入SQL列

Asp.net 将下拉框中的日期插入SQL列,asp.net,c#-4.0,sql-server-2014,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(connect

这是我的密码:

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个下拉框(下拉日、下拉月、下拉年)中选择的日期

问题是此代码(“+DropDownMonth.Text+”/“+DropDownDay.Text+”/“+DropDownYear.Text+”)不会执行此操作,因为他收到一个sql错误


如何才能成功实现我的目标?

尝试在“/”之间不使用单引号“”。

首先,不要对插入使用串联值,因为可能会遇到SQL注入问题。使用参数化查询。然后尝试在“/”之间不使用单引号“”。这样做没有任何方法吗?您得到的sql错误是什么?同时检查我编辑的评论。是!就是这样…你是对的,没有必要在破折号之间使用“。。。非常感谢。。Ευχαριστω Πολυ φιλε μου! :)没有什么!!我可以把它作为答案吗!Τίποτα χαρά μου!