Well yeah as the topic says, this is my sql question right now;
string date = "2006-11-12";
string sql = "SELECT * FROM spell_of_work WHERE date='{0}'",date);
problem is that my date column in the table is datetime and not a date so.. error!
i dont know if RLIKE or LIKE can help,wating for a reply!
herman
![]() |
0 |
![]() |
SELECT * FROM spell_of_work WHERE date=' " & date & " ' "
I put spaces in between the quotes, so they could be seen better - you don't want to put those spaces there.
David Wier
MCP/ASPInsider
ASPNet101.com - where to look first!
Control Grouper - easily control properties for multiple controls with one control!
Calendar Express - The Best HTML Calendar Generator on the web!
(Please 'Mark as Answer' when it applies)
![]() |
0 |
![]() |
string monday = "2006-12-19";
string sql = "SELECT * FROM spell_of_work WHERE date='" & monday & "'";i get following error:
Error 1 Operator '&' cannot be applied to operands of type 'string' and 'string'
Anyone?
herman
![]() |
0 |
![]() |
You are designating monday as a string - in your database, it's looking for a date -
try:
string datetime=........
David Wier
MCP/ASPInsider
ASPNet101.com - where to look first!
Control Grouper - easily control properties for multiple controls with one control!
Calendar Express - The Best HTML Calendar Generator on the web!
(Please 'Mark as Answer' when it applies)
![]() |
0 |
![]() |
hmm, how do u mean?
string monday = "2006-12-16";
string sql Datetime = "SELECT id,started FROM spell_of_work WHERE started='" &monday& "'";
errors~
herman
![]() |
0 |
![]() |
PLease use parameterized queries:string sql Datetime = "SELECT id,started FROM spell_of_work WHERE started=@started;Besides preventing SQL injection attacks, your code looks cleaner and you dont have to worry about where/how to put spaces/quotes etc.
***********************
Dinakar Nethi
Life is short. Enjoy it.
***********************
![]() |
0 |
![]() |
well ok thanks but that didnt solve my problem
still, u cant do string sql Datetime = "";
wonder how he ment.
herman
![]() |
0 |
![]() |
This is how you would do it in VB:
dim sql as string="SELECT * FROM spell_of_work WHERE date>=CAST(floor(CAST(@date AS float)) as datetime) AND date<CAST(floor(CAST(@date AS float))+1 AS datetime)"
dim conn as new sqlconnection(ConfigurationManager.ConnectionStrings("ConnectString").ConnectString)
dim cmd as new sqlcommand(sql,conn)
cmd.parameters.add("@date",sqldbtype.datetime).value=now
...
![]() |
0 |
![]() |
bah dont work, working with c# hehe
![]() |
0 |
![]() |
They are right - parameterized queries are the way to go - however, what I was talking about before was:
instead of:
string monday = "2006-12-16";
do
datetime monday = "2006-12-16";However, - here, note that since the system may see that as a specific DAY, I would recommend using something else - even adding an extra letter or two at the beginning, like:
datetime dtmonday = "2006-12-16";Then -
string sql = "SELECT * FROM spell_of_work WHERE date='" & dtmonday & "'";Do check out parameterized queries - I know I have a 2 part tutorial on it, though the core of the example code is VB (http://aspnet101.com/aspnet101/tutorials.aspx?id=1). This will tell you most of what you need to know about what it does, how to use it and why it's better.
David Wier
MCP/ASPInsider
ASPNet101.com - where to look first!
Control Grouper - easily control properties for multiple controls with one control!
Calendar Express - The Best HTML Calendar Generator on the web!
(Please 'Mark as Answer' when it applies)
![]() |
0 |
![]() |
Well im having a function that get the first day of the week looks like this:
int iWeek = week;
int iYear = year;
DateTime dtDate = DateTime.Parse("01/01/" + year.ToString());
dtDate = dtDate.AddDays(7 * iWeek);
//ADD DAY UNTILL FIRST MONDAY IS FOUND
while (dtDate.DayOfWeek != DayOfWeek.Monday)
{
dtDate = dtDate.AddDays(1);
}
string strMonday = dtDate.ToString("yyyy/MM/dd");DateTime dtMonday = Convert.ToDateTime(strMonday);
string sql = "SELECT * FROM spell_of_work WHERE date='" & dtMonday & "'";
that should help u guys more,
herman
![]() |
0 |
![]() |
and up we go!
![]() |
0 |
![]() |