Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.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
C# CS1503 C参数1:无法从“字符串”转换为“System.Data.SqlClient.SqlCommand”_C#_Winforms_Insert - Fatal编程技术网

C# CS1503 C参数1:无法从“字符串”转换为“System.Data.SqlClient.SqlCommand”

C# CS1503 C参数1:无法从“字符串”转换为“System.Data.SqlClient.SqlCommand”,c#,winforms,insert,C#,Winforms,Insert,CS1503 C参数1:无法从“字符串”转换为“System.Data.SqlClient.SqlCommand” 这里有一些代码,它可能会帮助你 using (SqlConnection conn = new SqlConnection("connectionString")) { // Open Connection conn.Open(); // Define Sql Command SqlC

CS1503 C参数1:无法从“字符串”转换为“System.Data.SqlClient.SqlCommand”


这里有一些代码,它可能会帮助你

using (SqlConnection conn = new SqlConnection("connectionString"))
{
            // Open Connection
            conn.Open();

            // Define Sql Command
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "SQL Query";
            cmd.Connection = conn;

            // Your Adapter, Editted you are insert not get Data Comment
            //SqlDataAdapter adapter = new SqlDataAdapter();
            //adapter.SelectCommand = cmd;

            cmd.ExecuteNonQuery();
}

但是你还是应该正确地检查你的代码;也许你应该在发布这样的问题之前仔细看看你的代码?这是非常自我解释的,如果您查看语法突出显示和查询语句的结尾,那么错误就非常明显了……SqlDataAdapter对象没有一个只接受一个字符串的构造函数:代码页对您造成6点伤害!请不要在没有任何解释的情况下发布代码,特别是关于问题的内容。
using (SqlConnection conn = new SqlConnection("connectionString"))
{
            // Open Connection
            conn.Open();

            // Define Sql Command
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "SQL Query";
            cmd.Connection = conn;

            // Your Adapter, Editted you are insert not get Data Comment
            //SqlDataAdapter adapter = new SqlDataAdapter();
            //adapter.SelectCommand = cmd;

            cmd.ExecuteNonQuery();
}