oledb

What is IMEX within OLEDB connection strings?

自闭症网瘾萝莉.ら 提交于 2019-11-26 20:34:53
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=localhost;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=2" What is the purpose of IMEX=2 in the above connection string? Steve From ConnectionStrings "If you want to read the column headers into the result set (using HDR=NO even though there is a header) and the column data is numeric, use IMEX=1 to avoid crash. To always use IMEX=1 is a safer way to retrieve data for mixed data columns. .." Please note that the IMEX value can be very important when you need to write back data to the Excel. A fast search on Internet on IMEX found numerous articles

OleDbParameters and Parameter Names

夙愿已清 提交于 2019-11-26 19:04:38
I have an SQL statement that I'm executing through OleDb, the statement is something like this: INSERT INTO mytable (name, dept) VALUES (@name, @dept); I'm adding parameters to the OleDbCommand like this: OleDbCommand Command = new OleDbCommand(); Command.Connection = Connection; OleDbParameter Parameter1 = new OleDbParameter(); Parameter1.OleDbType = OleDbType.VarChar; Parameter1.ParamterName = "@name"; Parameter1.Value = "Bob"; OleDbParameter Parameter2 = new OleDbParameter(); Parameter2.OleDbType = OleDbType.VarChar; Parameter2.ParamterName = "@dept"; Parameter2.Value = "ADept"; Command

Excel cell-values are truncated by OLEDB-provider

巧了我就是萌 提交于 2019-11-26 18:22:12
问题 I'm using the OleDbConnection class to retrieve data from an Excel 2000/2003 workbook: string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filename + ";" + "Extended Properties=\"Excel 8.0;IMEX=1\";"; OleDbConnection connection = new OleDbConnection(connectionString); connection.Open(); // code to get table name from schema omitted var dataAdapter = new OleDbDataAdapter(string.Format("SELECT * FROM [{0}]", name),connection); var myDataSet = new DataSet();

OLEDB Parameterized Query

假如想象 提交于 2019-11-26 18:01:39
public void LoadDB() { string FileName = @"c:\asdf.accdb"; string query = "SELECT ID, Field1 FROM Table1 WHERE ID=? AND Field1=?"; string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName; OleDbConnection odc = new OleDbConnection(strConn); dAdapter = new OleDbDataAdapter(); OleDbCommand cmd = new OleDbCommand(query,odc); cmd.Parameters.Add("?", OleDbType.Integer, 5).Value = 1234; cmd.Parameters.Add("?", OleDbType.BSTR, 5).Value ="asdf"; dAdapter.SelectCommand = cmd; ds = new DataSet(); dAdapter.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; } I'm trying to use

Trying to insert DateTime.Now into Date/Time field gives “Data type mismatch” error

别说谁变了你拦得住时间么 提交于 2019-11-26 17:59:06
If I try to write a datetime to a record in an MS-Access database the easy way, like this cmd.CommandText = "INSERT INTO [table] ([date]) VALUES (?)"; cmd.Parameters.AddWithValue("?", DateTime.Now); I get an exception saying "Data type mismatch in criteria expression." Can anybody tell me why? What goes wrong here? After a little experimentation, I found that I can make it work if I write OleDbParameter parm = new OleDbParameter("?", OleDbType.Date); parm.Value = DateTime.Now; cmd.Parameters.Add(parm); but doing it like this seems less neat, less straightforward. Why is this necessary? Am I

Access SQL syntax error when using OleDbCommandBuilder

元气小坏坏 提交于 2019-11-26 17:48:37
问题 I am going to INSERT data in Access Database using OleDbDataAdapter in C# but i got an error with message Syntax Error in INSERT INTO Command BackgroundWorker worker = new BackgroundWorker(); OleDbDataAdapter dbAdapter new OleDbDataAdapter(); OleDbConnection dbConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\PMS.mdb"); worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += InsertJob; worker.ProgressChanged += InsertJobCompleted

OLEDB Parameterized Query

♀尐吖头ヾ 提交于 2019-11-26 17:26:10
问题 public void LoadDB() { string FileName = @"c:\asdf.accdb"; string query = "SELECT ID, Field1 FROM Table1 WHERE ID=? AND Field1=?"; string strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + FileName; OleDbConnection odc = new OleDbConnection(strConn); dAdapter = new OleDbDataAdapter(); OleDbCommand cmd = new OleDbCommand(query,odc); cmd.Parameters.Add("?", OleDbType.Integer, 5).Value = 1234; cmd.Parameters.Add("?", OleDbType.BSTR, 5).Value ="asdf"; dAdapter.SelectCommand = cmd; ds =

Passing query parameters in Dapper using OleDb

旧街凉风 提交于 2019-11-26 17:12:14
问题 This query produces an error No value given for one or more required parameters : using (var conn = new OleDbConnection("Provider=...")) { conn.Open(); var result = conn.Query( "select code, name from mytable where id = ? order by name", new { id = 1 }); } If I change the query string to: ... where id = @id ... , I will get an error: Must declare the scalar variable "@id". How do I construct the query string and how do I pass the parameter? 回答1: The following should work: var result = conn

Parameterized query for inserting values

夙愿已清 提交于 2019-11-26 17:09:30
问题 I was trying to insert values into an Access database using a parameterized query: private void button1_Click(object sender, EventArgs e) { if (validationcontrol()) { MessageBox.Show(cmbjobcode.SelectedValue.ToString()); OleDbConnection oleDbConnection1 = new System.Data.OleDb.OleDbConnection(connString); oleDbConnection1.Open(); OleDbCommand oleDbCommand1 = new System.Data.OleDb.OleDbCommand("INSERT INTO quotationmastertable (quotationcode ,jobcode , jobpk , sillabordercharges ,

Programmatically finding an Excel file's Excel version

萝らか妹 提交于 2019-11-26 16:57:17
问题 I'm using an OleDbConnection to connect to a spreadsheet from a C# program. One of the parameters in the connection string is the Excel version. "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Book1.xls;Extended Properties=" Excel 8.0 ;HDR=YES" Given the path of an Excel file how can I find out which Excel format version it uses? Thanks in advance, T. 回答1: Download OLE File Property Reader. Register dsofile.dll with regsvr32 and add it as a reference in your application. The following code