Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
salam
i'm trying to make a query and in the condition i'm using "BETWEEN" to get what i want in a specific periode.the start date and the end date are in maskedtextbox (short date)
this is a part of query
C#
where
dd.finance=0
and dd.Date_depot between  '" + Convert.ToDateTime(maskedTextBox1.Text)+" ' and ' " +Convert.ToDateTime(maskedTextBox2.Text)"'
and dd.annule=0
and dd.XTransfertSortant=0

the probleme is when i write the query in this way i got an error that ";" is missed before " and dd.annule=0 "

or erro " newline in constant "
with this code
C#
dd.finance=0
and dd.Date_depot between '"+maskedTextBox1.Text+"' and '"+ maskedTextBox2.Text+"'
and dd.annule=0

or this error " Syntax error converting datetime from character string. "
ith this code
C#
dd.finance=0 
  and dd.Date_depot between 'maskedTextBox1.Text' and 'maskedTextBox2.Text'


any solution plz
Posted

In first e.g
where
dd.finance=0
and dd.Date_depot between '" + Convert.ToDateTime(maskedTextBox1.Text)+" ' and ' " +Convert.ToDateTime(maskedTextBox2.Text)+"' //forgot '+' sign
and dd.annule=0
and dd.XTransfertSortant=0


try to use
DateTime.Parse( maskedTextBox1.Text );
to convert string to DateTime

and check the format of the date also
 
Share this answer
 
v3
Comments
sidali.kadi 31-Mar-14 6:46am    
i got this error "newline in constant"
it's ok i solved it i added "@" at the end
like this
C#
dd.finance=0 
and dd.Date_depot between '" + Convert.ToDateTime(maskedTextBox1.Text)+"'  and  '" +Convert.ToDateTime(maskedTextBox2.Text)+@"'
and dd.annule=0
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900