开发者

Query Returns nothing

I had a datagrid table tblpaymentview and i want to get the values from a database i had declared concstring and write code as

private void btnsearch_Click(object sender, EventArgs e)
{
  try
  {
    DateTime time = dtpfromDate.Value;
    String query = "Select jobcode,companyName,vehicleno,shipment开发者_如何学编程date,totalamount,advance,drivername,fromPlace,destination from jobmastertable  where (shipmentdate='"+time+"')";
    OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, connString);
    DataSet ds = new DataSet();
    dAdapter.Fill(ds);
    tblpaymentview.DataSource = ds.Tables["tblpaymentview"].DefaultView;
  }
  catch (Exception)
  {
    MessageBox.Show("The application had met with some errors please restart  the application :\n error:closer MSAccess files");
  }
}

Please can anyone help me. I also tried (Datepicker)dtpfromdate.value.toshortdateString() also


You sure you dont get an exception?

Secondly, why do you assume the table is called tblpaymentview when it comes from jobmastertable ?


I don't know if this is your problem, but ACCESS usually uses # instead of ' for date format.


In these situations, you may use OleDBParameters:

    String query = "Select jobcode,companyName,vehicleno,shipmentdate,totalamount,advance,drivername,fromPlace,destination from jobmastertable  where (shipmentdate=@shipmentdate)";
dAdapter.SelectCommand.Parameters.AddWithValue("@shipmentdate", time);


I would query from your table on some other condition, just to get an example of the true data type of your "shipmentdate" column. Is it really a date? but actually a date/time field. or a date/time stored as a character. I would change it to a parameterized query and add as appropriate type... such as datetime field and NOT by string concatination.


Try By Bindingsource as below:

BindingSource bindingsource1;
DataSet ds;
String query = "Select jobcode,companyName,vehicleno,shipmentdate,totalamount,advance,drivername,fromPlace,destination from jobmastertable  where (shipmentdate='"+time+"')";
OleDbDataAdapter dAdapter = new OleDbDataAdapter(query,Your Connection);
ds = new DataSet();
dAdapter.Fill(ds);
bindingsource1 = new BindingSource();
bindingsource1.DataSource = ds;
bindingsource1.DataMember = ds.Tables[0].TableName;
tblpaymentview.DataSource = bindingsource1;

Hope this works...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜