Dtaset holds a table called "Table", not the table I pass in?

Posted by dotnetdev on Stack Overflow See other posts from Stack Overflow or by dotnetdev
Published on 2010-04-04T21:31:36Z Indexed on 2010/04/04 21:33 UTC
Read the original article Hit count: 174

Filed under:

Hi,

I have the code below:

        string SQL = "select * from " + TableName;

        using (DS = new DataSet())
        using (SqlDataAdapter adapter = new SqlDataAdapter())
        using (SqlConnection sqlconn = new SqlConnection(connectionStringBuilder.ToString()))
        using (SqlCommand objCommand = new SqlCommand(SQL, sqlconn))
        {
            sqlconn.Open();
            adapter.SelectCommand = objCommand;
            adapter.Fill(DS);
        }

        System.Windows.Forms.MessageBox.Show(DS.Tables[0].TableName);

        return DS;

However, every time I run this code, the dataset (DS) is filled with one table called "Table". It does not represent the table name I pass in as the parameter TableName and this parameter does not get mutated so I don't know where the name Table comes from. I'd expect the table to be the same as the tableName parameter I pass in?

Any idea why this is not so?

Thanks

© Stack Overflow or respective owner

Related posts about c#