1

I have tried to use sql parameter on one of my queries and noticed when ever i do so, it just doesn't return anything! while the none parametrized one works just fine.
Why is it ?
None parametrized one :

string columnCommentsQuery = string.Format("SELECT   * FROM   ::fn_listextendedproperty(NULL, 'user', 'dbo', 'table', '{0}', 'column', default)", table[2].ToString());

    DataTable comments = new DataTable();
    SqlCommand sql = new SqlCommand(columnCommentsQuery, conn);
    conn.Open();
    SqlDataAdapter da = new SqlDataAdapter(sql);
    da.Fill(comments);
    conn.Close();

Parametrized one:

string columnCommentsQuery = "SELECT   * FROM   ::fn_listextendedproperty(NULL, 'user', 'dbo', 'table', @tb, 'column', default)";
     DataTable comments = new DataTable();
     SqlCommand sql = new SqlCommand(columnCommentsQuery, conn);
     sql.Parameters.AddWithValue("tb", "'" + table[2].ToString() + "'");
     conn.Open();
     SqlDataAdapter da = new SqlDataAdapter(sql);
     da.Fill(comments);
     conn.Close();

1 Answer 1

5

Try changing

sql.Parameters.AddWithValue("tb", "'" + table[2].ToString() + "'");

to

sql.Parameters.AddWithValue("tb", table[2].ToString() );

hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.