I do this in my sql managment studio
SELECT * FROM SMSMessage WHERE respondCode IS NULL
and I got results
I want to do that query from C#
I tried this:
string query = "SELECT * FROM SMSMessage WHERE respondCode IS @respondCode";
SqlConnection con = new SqlConnection(Utilities.getConnectionString());
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@respondCode", DBNull.Value);
I got this exxception :
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Incorrect syntax near '@respondCode'.
why please?
I also tried
string query = "SELECT * FROM SMSMessage WHERE respondCode IS NULL";
and I got empty results.
Uupdate
string query = @"SELECT *
FROM SMSMessage
WHERE (respondCode = @respondCode)
OR (@respondCode IS NULL AND respondCode IS NULL)";
SqlConnection con = new SqlConnection(Utilities.getConnectionString());
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@respondCode", DBNull.Value);
con.Open();
using (con)
{
DataTable results = new DataTable();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(results);
string query = "SELECT * FROM SMSMessage WHERE respondCode IS NULL";"and got empty results. Sounds like you are connecting to a different instance/database than the one you are connecting to in SSMS then.sda.Fill(results);and see if you have positive row count?