oledb

Microsoft Access UPDATE command using C# OleDbConnection and Command NOT working

∥☆過路亽.° 提交于 2019-11-28 02:07:15
I'm using Microsoft Access unfortunately because of higher forces and trying to update a record with no luck. This is the code: private void UpdateContact(Contact contact) { using (OleDbConnection db = new OleDbConnection(_connString)) { string query = "UPDATE [Contact] SET [FirstName] = @FirstName, [LastName] = @LastName, [MobileNumber] = @MobileNumber WHERE [Id] = @Id"; OleDbCommand cmd = new OleDbCommand(query, db) { CommandType = CommandType.Text }; cmd.Parameters.AddWithValue("@Id", contact.Id); cmd.Parameters.AddWithValue("@FirstName", contact.FirstName); cmd.Parameters.AddWithValue("

DBNull in non-empty cell when reading Excel file through OleDB

青春壹個敷衍的年華 提交于 2019-11-28 02:00:58
I use OleDB to read an Excel file. One of the columns has a "Common" format and contains both strings with letters and values consisting of numbers only. String values are retrieved without problem, but pure numerical values are retrieved as DBNull . How to solve? I use the following connection string to open Excel 2003 file (xls): "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\file.xls; Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\"" I found some documentation on Microsoft's website that applies to your scenario. They recommend converting all the numerics to strings. http://support

Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done

ぃ、小莉子 提交于 2019-11-28 01:55:57
I am running following code /*Fetchinch Last CustID from custMaster*/ int ID = 0; try { con.Open(); da = new OleDbDataAdapter("select max(Id) from custMaster",con); DataSet ds = new DataSet(); da.Fill(ds); for(int i=0;i<ds.Tables[0].Rows.Count;i++) ID=int.Parse(ds.Tables[0].Rows[i][0].ToString()); con.Close(); } catch (Exception ex) {} finally { con.Close(); } I am putting debugger from the first statement of try block and finding that error is coming when I am trying to open the connection. Error Text: Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if

Insert DataTable into Excel Using Microsoft Access Database Engine via OleDb

房东的猫 提交于 2019-11-28 01:42:17
问题 I came across instructions today for reading data from a Microsoft Excel file using an OleDbConnection on this website: OLE DB Providers This allows me to read in all the data from an Excel file: private const string EXCEL_CON = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};" + @"Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'"; public DataTable ExtractExcel(string fullFilename, string tableName) { var table = new DataTable(); string strCon = string.Format(EXCEL_CON, fullFilename); using

How to check if an OLEDB driver is installed on the system?

爷,独闯天下 提交于 2019-11-28 00:46:12
How can I make sure that a certain OLEDB driver is installed when I start my application? I use ADO from Delphi and would like to display a descriptive error message if the driver is missing. The error that's returned from ADO isn't always that user-friendly. There are probably a nice little function that returns all installed drivers but I haven't found it. Jeremy Mullin Each provider has a GUID associated with its class. To find the guid, open regedit and search the registry for the provider name. For example, search for "Microsoft Jet 4.0 OLE DB Provider". When you find it, copy the key

System.Data.OleDb.OleDbException: Could not find installable ISAM

妖精的绣舞 提交于 2019-11-28 00:18:28
I have scoured the net, and found many people asking this, yet none have fixed my answer. I have a Connection Class, and a Method that uses that Class in a page. DataConn.cs public static OleDbConnection ConnectExcel() { //Store the connection details as a string string connstr = String.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=pricelist.xlsx;Extended Properties=Excel 12.0 Xml;HDR=YES"); //Initialise the connection to the server using the connection string. OleDbConnection oledbConn = new OleDbConnection(connstr); //Open the connection, we do this here so we can instantly be able

Data type mismatch in criteria expression | Access, OleDb, C#

女生的网名这么多〃 提交于 2019-11-27 23:13:59
I read/update data from MS Access using C#. My code is: public static void UpdateLastLogin(int userid, DateTime logintime) ///logintime = DateTime.Now { string sql = @"UPDATE [Customers] SET [LastLogin]=?"; OleDbParameter[] prms = new OleDbParameter[] { new OleDbParameter("@LastLogin",logintime) }; using (DAL dal = new DAL()) { dal.UpdateRow(sql, false, prms); } } When it comes to Dates, I having trouble. This throws a "Data type mismatch in criteria expression." error. (I removed WHERE clause for keeping it simpler) Am I suuposed to enclose [LastLogin]=? question mark with single quotes, #

Check if ADODB connection is open

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 22:52:57
I use the following from within some excel procedures to establish a connection to our database. Private Const strConn As String = _ "PROVIDER=SQLOLEDB.1 ..." Sub OpenConnection() Set cn = CreateObject("ADODB.Connection") cn.Open strConn cn.CommandTimeout = 0 Set rs = CreateObject("ADODB.Recordset") Set rs.ActiveConnection = cn End Sub In subsequent code I open the connection using various SQL strings. I'd like to test if rs is open so I know that it needs to be closed but the following does not work. How can I change the condition in the following to work? If (rs.Open = True) Then rs.Close

Import Excel to Datagridview

醉酒当歌 提交于 2019-11-27 21:37:50
I'm using this code to open an excel file and save it in a DataGridView: string name = "Items"; string constr = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source=" + Dialog_Excel.FileName.ToString() + "; Extented Properties =\"Excel 8.0; HDR=Yes;\";"; OleDbConnection con = new OleDbConnection(constr); OleDbDataAdapter sda = new OleDbDataAdapter("Select * From [" + name + "$]", con); DataTable data = new DataTable(); sda.Fill(data); grid_items.DataSource = data; As explained on: This youtube link But I get an ISAM error. Any suggestion? Since you have not replied to my comment above, I am

Return value of a select statement

↘锁芯ラ 提交于 2019-11-27 21:26:08
问题 I have this little problem. I want to retrieve the resulting value of a select statement into a string variable. Like this OleDbCommand cmd1 = new OleDbCommand(); cmd1.Connection = GetConnection(); cmd1.CommandText = "SELECT treatment FROM appointment WHERE patientid = " + text; cmd1.ExecuteNonQuery(); I want the to place the selected treatment value into a string variable. How can i do this. Thanks 回答1: Use ExecuteReader() and not ExecuteNonQuery(). ExecuteNonQuery() returns only the number