Hullo Good Friends,
I need your help. Please Help me. Thank You.I encounter a very interesting problem regarding Window Application using C#NET3.5, SqlServer2000. Problem using SQL String using Date Between statement.
I am using date parameters from 2 input textbox to retrieve Customer Invoice table to fill the DataGridView and it's not working as the problem seem to be caused my the SQL String Statement : OrderDate Between DateFrom and DateTo
Error message:The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value
private void FFillDataGridView()
{
DateTime DateFrom =Convert.ToDateTime(this.txtDateFrom.Text);<-causing error
DateTime DateTo =Convert.ToDateTime(this.txtDateTo.Text); <- causing errror message
string strsql = " Select OrderID, ProductID,";
strsql += " Convert(varchar(10), OrderDate, 103) as [OrderDate], ";
strsql += " Convert(Numeric(10,2), unitprice, 2) as [UnitPrice], ";
strsql += " From tblInvoices ";
strsql += " Where (CustomerID = '" + strCustID + "')";
strsql += " AND (OrderDate between DateFrom + "'"; <-- not working
strsql += " AND '" + DateTo + "')"; <-- not working
Try
sqlconn = new SqlConnection(connstr); sqlconn.Open();
DA = new SqlDataAdapter(strsql, sqlconn);
DS = new System.Data.DataSet();
DS.Clear();
DA.Fill(DS, "Invoice");
this.dataGridView1.DataSource = DS.Tables["Invoice"];
}
Catch (Exceptional Ex)
{ messagebox.show(ex.message); }
Thank you for helping me.
Have A Good Day,
Cheers,
Lennie