My Access database does not returns any row with a xsd DataSet
I have to import an Access database. When I copy/pasted the mdb file into the application, it created a corresponding XSD dataset, so I went along with it (I figured it would be much easier than to query it using ODBC).
I try to query the database using these lines : var dsAccess = new data.DATAGESTIONDataSet();
var RaisonSociales = from rs in dsAccess.Tb_Raison_Soc
开发者_如何学运维 select rs;
foreach (var rs in RaisonSociales)
{
Console.WriteLine(rs.Raison_Soc);
}
Unfortunately, the select statement does not return any row.
The "Linq to SQL class" and ADO.Net Entity Framework do not support MS Access :(
Any idea ?
ThanksEDIT : here is the solution, thanks to @Daniel Hilgart :
var cn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ImportSerce.Properties.Settings.DATAGESTIONConnectionString"].ToString());
var cmd = new OleDbCommand("SELECT * FROM [Tb_Raison_Soc]", cn);
var da = new OleDbDataAdapter(cmd);
var tds = new data.DATAGESTIONDataSet();
da.Fill(tds, tds.Tb_Raison_Soc.TableName);
var rsMS = from rs in tds.Tb_Raison_Soc
select rs;
foreach (var rs in rsMS)
{
Console.WriteLine(rs.Raison_Soc);
}
Not exactly as pretty, and a bit cumbersome to work with, but at least it works. Thanks !
You need to fill the DataSet
by calling Fill
on the generated DataAdapter passing your DataSet
and the table name. More info can be found here: http://support.microsoft.com/kb/320714
精彩评论