我有一个datagrid表tblpaymentview,我想从数据库中获取值 我已经宣布了concstring 并将代码编写为
private void btnsearch_Click(object sender, EventArgs e)
{
try
{
DateTime time = dtpfromDate.Value;
String query = "Select jobcode,companyName,vehicleno,shipmentdate,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");
}
}
任何人都可以帮助我。我也试过(Datepicker)dtpfromdate.value.toshortdateString()也
答案 0 :(得分:0)
你确定你没有例外吗?
其次,为什么假设该表来自tblpaymentview
时会被称为jobmastertable
?
答案 1 :(得分:0)
我不知道这是不是你的问题,但是ACCESS通常使用#代替'来代替日期格式。
答案 2 :(得分:0)
在这些情况下,您可以使用OleDBParameters:
String query = "Select jobcode,companyName,vehicleno,shipmentdate,totalamount,advance,drivername,fromPlace,destination from jobmastertable where (shipmentdate=@shipmentdate)";
dAdapter.SelectCommand.Parameters.AddWithValue("@shipmentdate", time);
答案 3 :(得分:0)
我会从您的表中查询其他条件,只是为了获得“shippingdate”列的真实数据类型的示例。真的是约会吗?但实际上是一个日期/时间字段。或者存储为角色的日期/时间。我会将其更改为参数化查询并添加适当的类型...例如datetime字段,而不是字符串连接。
答案 4 :(得分:0)
按Bindingsource尝试如下:
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;
希望这有效......