To prep my question defensively, I’ve utilized Google, Bing and StackOv prior to posting :-). Also, I’m new to MVC3 and still grappling with the syntactical intricacies of the framework.
I have an error in my SQL statement in the code block below which is bugging me quite a bit. The syntax appears correct. I simplified the SQL statement with a Select * From.. and it returns data just fine.
Also, if there is a better way to do this (without using an EF object), definitely open to suggestions. I really like the flexibility and control of seeing the SQL Statement – either that, or just used to it as form of habit :-).
Thanks in advance!!
@using System.Data.SqlClient;
@using System.Configuration;
@{
Layout = null;
}
@{
SqlConnection cn = null;
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlConn"].ToString());
cn.Open();
SqlCommand cmd = new SqlCommand((@"SELECT DISTINCT" +
"tblSBT.sname," +
"tblSBDetails.sid," +
"tblSBDetails.assignedtrack," +
"tblSBDetails.maxtrack," +
"tblSBDetails.currentvals," +
"tblSBDetails.maxvals," +
"tblSBDetails.lastupdated" +
"FROM" +
"tblSBT (NOLOCK)" +
"LEFT OUTER JOIN" +
"tblSBDetails (NOLOCK)" +
"ON" +
"tblSBT.sid = tblSBDetails.sid" +
"WHERE" +
"tblSBDetails.lastupdated > DateADD(n, -5, GETDATE())"+
"ORDER BY" +
"tblSBT.sname" +), cn);
var myreader = cmd.ExecuteReader();
}
If you’re using the @ symbol, you don’t need to concatenate your strings like how you are doing it. It’s also not the most efficient way of writing that piece of code when you’re joining strings like that.