0
 public void SPROC_LoadGroups()
        { 
            //This gets the table name.
            string tablename = cboNetChannel.SelectedItem.ToString();

            SqlConnection sqlConnectionCmdString = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Rick\Documents\Visual Studio 2010\Projects\Server\database\ClientRegit.mdf;Integrated Security=True;User Instance=True");

            //This is the table name and Query that identifies with the selected table
            string Command = "SELECT Client_Groups" + "FROM" + tablename;

            SqlCommand sqlCommand = new SqlCommand(Command, sqlConnectionCmdString);

            SqlDataAdapter objDA = new SqlDataAdapter(sqlCommand);

            DataSet dsGroups = new DataSet();

            objDA.Fill(dsGroups, "dtGroup");

            cboExistingG.DataSource = dsGroups.Tables["dtGroup"];
            cboExistingG.DisplayMember = "Client_Groups";
            //cboExistingG.ValueMember = "ID";


        }

我得到的错误是这个{“'-'附近的语法不正确。”}

我遇到的情况是可以查询名称类似于 GUID 值的表我的表名是 43d5377-0dcd-40e6-b95c-8ee980b1e248

我正在生成使用名为 43d5377-0dcd-40e6-b95c-8ee980b1e248 的网络数据表标识的组。表名是允许的,SQL 不禁止此类表名。

这是我收到错误的代码,我通过创建一个允许我使用所选表值识别查询的查询来进行表映射。

4

3 回答 3

3

如果您的表名类似于 GUID 添加[]

就像是:

     string Command = "SELECT Client_Groups FROM [" + tablename+ "]";

此致

于 2013-07-23T01:01:09.787 回答
1

您在这两个字符串的连接之间缺少一个空格:

 "SELECT Client_Groups" + "FROM"

改成

"SELECT Client_Groups " + "FROM "
于 2013-07-23T01:02:19.637 回答
0

SqlCommand cmd;

cmd = new SqlCommand("SELECT client_Groups FROM Table name where name='" + txtbox.Text + "', lastname='" + txtbox.Text + "'", con);

于 2013-07-23T02:06:07.927 回答