【发布时间】:2017-06-01 20:29:09
【问题描述】:
我想从其他表创建新表并发送电子邮件。但是,它在sda.Fill(dt); 上一直出现错误
System.Data.SqlClient.SqlException:'(' 附近的语法不正确。 关键字“打开”附近的语法不正确。
private DataTable GetData()
{
string connString = @"Data Source=aa.database.windows.net;Initial Catalog=aa;Persist Security Info=True;User ID=aa;Password=aa";
string query = "CREATE TABLE new_table AS(SELECT ID, Employee, Name, Open Date, Task FROM tblEmployees, tblEmployees, Stores, Stores, tblTasks)";
using (SqlConnection con = new SqlConnection(connString))
{
using (SqlCommand comm = new SqlCommand(query))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
comm.Connection = con;
sda.SelectCommand = comm;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}
}
【问题讨论】:
-
请将错误信息添加到问题中。
-
这真的是mysql吗?因为如果是这样,您需要使用
MySqlConnection、MySqlCommand等,而不是SqlConnection等。 -
你为什么首先使用 DataTable?电子邮件与此有什么关系?
-
我不知道这是否是在 mysql 上创建表的正确语法,但无论哪种方式都不会返回结果集。我认为您不想创建表格,您可能只想选择。
-
@Crowcoder 我添加它。哦,是的,它不是 mysql。