Reputation: 63
im in a project and now im stuck on this. I need to read from a query to sql somedates and is id, and if that date if ending(lets say 20days range) , i will write something like "The item with id=? will end in 20days"
So far i got this
SqlConnection myCon = new SqlConnection(connectionString);
SqlCommand myCommand = new SqlCommand();
myCommand.CommandText = "SELECT * FROM cmsPropertyData WHERE contentNodeId IN (SELECT contentNodeId FROm cmsPropertyData WHERE propertytypeid = 138 AND dataNtext LIKE '41')AND propertytypeid = 137 AND dataNtext IS NOT NULL AND dataNtext NOT LIKE ''";
myCommand.Connection = myCon;
myCon.Open();
SqlDataReader Reader;
Reader = myCommand.ExecuteReader();
while (Reader.Read())
{
string getdatas = Reader["dataNtext"].ToString();
Response.Write(getdatas);
}
But like this i get all the datas into one single string and i dont know even witch id she belongs to. Im problably doing the wrong way , so if someone can help i would appreciate :)
Upvotes: 0
Views: 60
Reputation: 1447
Well your query is not clear. But if you want to find out if a row within 20 days range or not you do the following:
SELECT * FROM cmsPropertyData WHERE DATEDIFF(dd,dataNtext,GETDATE()) <= 20
Upvotes: 1