I have to use the “@”(I don’t know it’s name). I can use it in update delete or insert statements but I cannot use it in there it gives URL MUST BE DECLARED
//SQL string to count the amount of rows within the OSDE_Users table
string sql = "SELECT * FROM RSSFeeds where URL = @URL";
SqlCommand cmd = new SqlCommand(sql, Connect());
cmd.Parameters.Add("@URL", SqlDbType.VarChar, 500).Value = url;
closeConnection();
SqlDataAdapter adapt = new SqlDataAdapter(sql, Connect());
DataSet ds = new DataSet();
adapt.Fill(ds);
// result of query filled into datasource
adapt.Dispose();
closeConnection();
return ds;
I can only suppose that this line is not correct:
Probably URL is not an Int but a NVarChar or other character type
If this is the case then change your line in this way
(255 is the supposed length of your field URL)
And, by the way, ‘@’ is called “Parameter Prefix”
EDIT: Seeing the last edit from the OP I update my answer to show what I think is the correct way to go.
What I have changed:
usingstatement thatis guaranteed to close/dispose objects
reuse without creating another one
the @URL parameter reaches the Sql)
The OP used a closeConnection() and we don’t see the internal of this method, but I think that
usingis enough to close and dispose the connection.EDIT: The line that creates SqlDataAdapter should be