MySQL MySqlCommand


So far I have,

MySqlConnection conn1 = new MySqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ag"].ConnectionString);
            string table_name = year + report_type.SelectedValue.ToString();
       MySqlDataAdapter da = new MySqlDataAdapter();
       da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
        string qry= "select filename from @name";
    da.SelectCommand = new MySqlCommand(qry, conn1);
    //da.SelectCommand.Parameters.Add("@name", MySqlDbType.Text);
    //da.SelectCommand.Parameters["@name"].Value = table_name;
    da.SelectCommand.Parameters.AddWithValue("@name", table_name);
    TextBox1.Text = qry;
        var dt = new DataTable();

        GridView1.DataSource = dt;

I cannot get table_name from in above query.  If I hard code the value of table_name =2013 I get results.
What am I doing wrong?
Who is Participating?
guru_samiConnect With a Mentor Commented:
You can't pass table name in the Sql Parameter. Instead you can append the variable to your sql query.
string qry= "select filename from " + table_name;

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.