I'm trying to use a SQL request. Therefore I'd like to use the interface IDbCommand
I've tried to add the requested value with parameters, but if I use my script, the query looks like
SELECT * FROM DB WHERE Data = @val
Then I get a SqlException
.
Can someone help me?
// "Using": - To make sure that the connection get closed correctly!
using (IDbConnection con = new SqlConnection(connectionstring))
{
try
{
/*
* Use this for Initialize that it is a SQL Server,
* IDbConnection is for every connection
*/
IDbCommand sql = con.CreateCommand();
var exprParam = sql.CreateParameter();
sql.CommandText = comand;
exprParam.Value = value;
exprParam.ParameterName = "@val";
sql.Parameters.Add(exprParam);
con.Open();
// Connect to DB. Timeout: 15 Sekunden
IDataReader rdr = sql.ExecuteReader();
// Build DataReader
while (rdr.Read())
// Read data from console
numberOfRows = Convert.ToInt32(rdr[0]);
}
catch(Exception ex)
{
}
}