这是我尝试的部分代码
SqlConnection con = new SqlConnection(@"Data Source=ANSARI-PC\;Initial Catalog=BMS;Integrated Security=True");
string tname = idc + "-InvoiceT";
string sql = "select count(*) from '"+ tname + "' ";
con.Open();
SqlCommand sda = new SqlCommand(sql, con);
SqlDataReader myreader;
myreader = sda.ExecuteReader();
int lid;
对于上述代码,我收到此错误,表示“ 2-InvoiceT”附近的语法不正确 2-InvoiceT是数据库“ idc”中的表名,包含2作为值。
答案 0 :(得分:-1)
更改
string sql = "select count(*) from '"+ tname + "' ";
到
string sql = "select count(*) from ["+ tname + "] ";