Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.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# 格式化包含双引号的长sql字符串_C#_Sql_Winforms - Fatal编程技术网

C# 格式化包含双引号的长sql字符串

C# 格式化包含双引号的长sql字符串,c#,sql,winforms,C#,Sql,Winforms,我有一个winform应用程序,它作为数据源连接到access数据库,因为我不能使用存储过程,这与Mysql不同,我正在拼命尝试执行查询并在数据网格视图框中填充相同的内容。(之前我想在access数据库查询中使用相同的excel) 但是我再一次被如何以正确的格式输入这个长sql所震惊,请帮助我如何在我的代码中封装这个sql字符串 private void FormMainMenu_Load(object sender, EventArgs e) { //

我有一个winform应用程序,它作为数据源连接到access数据库,因为我不能使用存储过程,这与Mysql不同,我正在拼命尝试执行查询并在数据网格视图框中填充相同的内容。(之前我想在access数据库查询中使用相同的excel) 但是我再一次被如何以正确的格式输入这个长sql所震惊,请帮助我如何在我的代码中封装这个sql字符串

private void FormMainMenu_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'cSCDataSet.master_table' table. You can move, or remove it, as needed.
            this.master_tableTableAdapter.Fill(this.cSCDataSet.master_table);
            dataGridView1.DataSource = Read();
        }

        private readonly OleDbConnectionStringBuilder _builder = new OleDbConnectionStringBuilder
        {
            Provider = "Microsoft.ACE.OLEDB.12.0",
            DataSource = "S:\\Customer_Service\\Wires\\Database for CSC\\Backend data of databse do not open\\CSC.accdb"
        };

        public DataTable Read()
        {
            var dt = new DataTable();

            using (var cn = new OleDbConnection { ConnectionString = _builder.ConnectionString })
            {

                using (var cmd = new OleDbCommand { Connection = cn })
                {
                    cmd.CommandText = @"TRANSFORM Count(Complaint_Number) AS [Total Numbers]
                                       SELECT Nature_of_problem, Count(Complaint_Number) AS[Total Numbers of Issues]
                                       FROM master_table
                                       GROUP BY Nature_of_problem
                                       PIVOT Format(Complaint_Received_On, "mmm") In("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); 
                    cn.Open();
                    dt.Load(cmd.ExecuteReader());
                }
            }

            return dt;

        }
    }
}

您可以使用双引号。


显然,您的问题与Winforms无关

只是我不知道如何将它格式化为包含双引号

在SQL中,字符串引号带有单引号,如

因此,如果您需要c#字符串形式的命令文本:


所以你给我们一个SQL语句,它不做你想做的事,你让我们给一个SQL语句,它做你想做的事。如果您编辑这个问题并添加您的需求,对我们来说不是更容易吗:您的SQL应该做什么?你的表的相关部分是什么?不,我有一个sql,它可以工作(你可以在代码中看到相同的),只是我不知道如何格式化它以包括双引号。如果你不反对,你也可以投票吗@拉维库马尔
SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');
const string sqlCommandText = @"
    SELECT * FROM Customers
    WHERE Country IN ('Germany', 'France', 'UK')";

cmd.CommandText = sqlCommandText;