Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Run C# statement Based Off of SQL Server Field Value

$
0
0

I have a SQL Server Table that contains a value of either 0 or -1.  And I have a C# statement set to read like so.  BUT it didn't execute and I was curious if it's becauause I have my C# code set to be "1" and it needs to be "-1"  Can someone with more knowledge let me know?

//Connection String & other variables established above
string query = "Select * from databaseAlpha WHERE Needed = @MT ORDER BY LastName ASC";

SqlCommand cmd = new SqlCommand(queryString, connection)
connection.Open();
if (DateTime.Now.Hour >= 15)
{
cmd.Parameters.AddWithValue("@MT", 1)
}
else
{
cmd.Parameters.AddWithValue("@MT", 0);
}
//Do More Here


Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>