【发布时间】:2017-10-24 09:12:30
【问题描述】:
string connection = ConfigurationManager.ConnectionStrings["Table"].ConnectionString;
using (SqlConnection con = new SqlConnection(connection))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Table", con))
{
using (SqlDataAdapter da = new SqlDataAdapter())
{
da.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
da.Fill(dt);//This line throws exception
return dt;
我有这段代码,我想用它从网格中获取选定的数据并插入到另一个表中。在调试时,它导致我在da.Fill(dt); 行出现异常。
以下是被抛出的异常:
System.Data.dll 中出现“System.Data.SqlClient.SqlException”类型的异常,但未在用户代码中处理
附加信息:关键字“Table”附近的语法不正确。
【问题讨论】:
-
你不应该使用名称 Table 作为一个表,因为它是 sql 的保留字
标签: c# sql sql-server ado.net keyword