I couldn't figure out how to get Edge history in c#.
I've tried this code:
DataSet ds = new DataSet();
string mySelectQuery = "SELECT * FROM " + "Container_n";
OleDbConnection myConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DataSource=" + #"C:\Users\user\AppData\Local\Microsoft\Windows\WebCache\WebCacheV01.dat" + ";Extended Properties=\"text;HDR=YES;FMT=Delimited\"");
OleDbDataAdapter dsCmd = new OleDbDataAdapter(mySelectQuery, myConnection);
//Fill the DataSet object
dsCmd.Fill(ds, "Packets");
myConnection.Close();
But the row dsCmd.Fill(ds, "Packets"); throws:
The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local
machine.
I don't want to install it on every computer that I use the app on.
Is there any other way of doing it?
Related
I have C# WinForms application that gets information from Excel sheet and stores it to my database, my code works fine on my PC but when I changed it an Error
System.InvalidOperationException: 'The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.'
display. I solved this problem by changing the project platform from x86 to x64 but when I launch the project with x64 I can't charge many files so I have to run it on x86. Guys any solutions?
Rq: My code:
String name = "Feuil1";
String constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" +
textBox_path.Text +
";Extended Properties='Excel 12.0 XML;HDR=YES;';";
OleDbConnection con = new OleDbConnection(constr);
OleDbCommand oconn = new OleDbCommand("Select * From [" + name + "$]", con);
con.Open();
OleDbDataAdapter sda = new OleDbDataAdapter(oconn);
DataTable data = new DataTable();
sda.Fill(data);
dataview1.DataSource = data;
using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["UR2k_CS.Properties.Settings.StoreConnectionString"].ConnectionString))
{
String query = "INSERT INTO dbo.Stock (RFID,name,refrence,prix,Stockdate) VALUES (#RFID,#name,#refrence,#prix,#Stockdate)";
connection.Open();
for (int i=0;i<dataview1.Rows.Count-1;i++)
{
using (SqlCommand command = new SqlCommand(query, connection))
{
if ((dataview1.Rows[i].Cells[0].Value.ToString()!=null)&&((!checkifexist(dataview1.Rows[i].Cells[0].Value.ToString()))) &&(dataview1.Rows[i].Cells[0].Value.ToString()!=""))
{
command.Parameters.AddWithValue("#RFID", dataview1.Rows[i].Cells[0].Value.ToString());
command.Parameters.AddWithValue("#name", dataview1.Rows[i].Cells[1].Value.ToString());
command.Parameters.AddWithValue("#refrence", dataview1.Rows[i].Cells[2].Value.ToString());
command.Parameters.AddWithValue("#prix", dataview1.Rows[i].Cells[3].Value.ToString());
command.Parameters.AddWithValue("#Stockdate", DateTime.Now);
command.ExecuteNonQuery();
}
}
}
connection.Close();
}
You need to download the 32 bit driver from here microsoft downloads (I think this is the correct one) but the difficulty you may run into is that a machine cannot have both the 64bit and 32bit versions installed side by side.
Using EPPlus is a more modern approach.
I have been attempting to query an excel file from C# using an OLEDB connection. There are no runtime errors when the program runs, but it returns no results. I have tried it with different excel files but have gotten a similar result.
edit: The excel file is located in the project directory. If I remove the excel file from the current location the program will get a file not found exception.
private void btnRun_Click(object sender, EventArgs e)
{
string strFileName = "playerData.xls";
string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strFileName + ";Extended Properties=" + "\"Excel 8.0;HDR=YES\"";
OleDbConnection conn = new OleDbConnection(connStr);
conn.Open();
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM [Sheet1$]";
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
dgsResults.DataSource = ds;
conn.Close();
}
Does anyone know why this returns no results?
Thanks,
You are using strFileName in the connStr yet you have not provided the path with it.
Should be along the lines of:
string strFileName = #"c:\excel location\playerData.xls";
Apparently the specific data table has to be referenced in the data binding process. Adding the following line after the fill() method has solved the issue.
da.Fill(ds);
dgsResults.DataSource = ds.Tables[0]; //this is the line to be added
I have multiple files having data files stored in them.
I want to read them with Odbc or jet engine and stored them into DataSets.
Any ideas how to do that?
I wrote this code but I get error that file is read only:
tring strConnString = #"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dirCSV + #";Extended Properties=""text;HDR=YES;FMT=Delimited""";
OleDbConnection conn = new OleDbConnection(strConnString);
OleDbCommand cmd = conn.CreateCommand();
cmd.CommandText = String.Format("SELECT * FROM [{0}]", fileNevCSV);
DataSet ds2 = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds2);
How can I get the data in a .dbf file using c#??
What I want to do is to read the data in each row (same column) to further process them.
Thanks.
You may create a connection string to dbf file, then using OleDb, you can populate a dataset, something like:
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=directoryPath;Extended Properties=dBASE IV;User ID=Admin;Password=;";
using (OleDbConnection con = new OleDbConnection(constr))
{
var sql = "select * from " + fileName;
OleDbCommand cmd = new OleDbCommand(sql, con);
con.Open();
DataSet ds = new DataSet(); ;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
}
Later you can use the ds.Tables[0] for further processing.
You may also check this article Load a DBF into a DataTable
I found out the accepted answer didn't work for me, as the .dbf files I'm working with are nested in a hierarchy of directories that makes the paths rather long, which, sadly, cause the OleDbCommand object to throw.
I found a neat little library that only needs a file path to work. Here's a little sample adapted from the examples on its GitHub page:
var file = "C:\\Path\\To\\File.dbf";
using (var dbfDataReader = new DbfDataReader(file))
{
while (dbfDataReader.Read())
{
var foo = Convert.ToString(dbfDataReader["FOO"]);
var bar = Convert.ToInt32(dbfDataReader["BAR"]);
}
}
For 64 bit systems I used the Microsoft ACE OLEDB 12.0 data provider, for that provider to work you have to install Microsoft's Access Database Engine 2010
So it looks a lot like the accepted answer but with the provider changed:
string constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\folder;Extended Properties=dBASE IV;User ID=Admin;";
using (OleDbConnection con = new OleDbConnection(constr))
{
var sql = "select * from " + fileName;
OleDbCommand cmd = new OleDbCommand(sql, con);
con.Open();
DataSet ds = new DataSet();
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
}
I have to create charts with dynamic datasource, I have a code. It does not show error but the graph is also not visible on runtime.
Here out_table is the name of my table and ADX is one of its column.
code:
OleDbConnection con1 = new OleDbConnection(#"PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=RS.accdb");
String sqlo = "Select ADX from " + out_table + "";
OleDbCommand myCommand = new OleDbCommand(sqlo, con1);
myCommand.Connection.Open();
OleDbDataReader myreader = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
chart1.DataBindTable(myreader, "ADX");
thanks for helping me. I have solved this problem, and for others, here is the solution.
here, ds is dataset
OleDbConnection con1 = new OleDbConnection(#"PROVIDER=Microsoft.ACE.OLEDB.12.0;DATA SOURCE=RS.accdb");
String sqlo = "Select * from " + out_table + "";
OleDbDataAdapter da1 = new OleDbDataAdapter(sqlo, con);
DataSet ds = new DataSet();
da1.Fill(ds, in_table);
DataView firstView = new DataView(ds.Tables[0]);
chart1.Series[0].Points.DataBindXY(firstView, "ID", firstView, "ADX");