oledb

Data type mismatch in criteria expression

断了今生、忘了曾经 提交于 2019-12-02 21:48:07
问题 myConnection.Open() rtb_Address.Clear() txt_Name.Clear() Dim str As String str = "SELECT * FROM table1 WHERE (cus_ID = '" & txt_ID.Text & "')" Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection) dr = cmd.ExecuteReader() While dr.Read() rtb_Address.Text = dr("cus_Addr").ToString txt_Name.Text = dr("cus_Name").ToString End While myConnection.Close() Error in dr = cmd.ExecuteReader() dr is declared as OleDbDataReader 回答1: cus_ID is probaly a numeric data type, but you try to query it

syntax error while inserting data into ms access table

不羁的心 提交于 2019-12-02 21:29:18
问题 I have a following code: OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=storage_db.accdb"); string sql = "INSERT INTO Client cname,phone,password) VALUES('"+textBox1.Text+"','"+textBox2.Text+"', '"+textBox3.Text+"')"; aConnection.Open(); OleDbCommand insert = new OleDbCommand(sql, aConnection); insert.ExecuteNonQuery(); aConnection.Close(); But when I try to insert data I am getting an exception syntax error in insert query. What am I doing

Syntax error in INSERT INTO Statement when writing to Access

…衆ロ難τιáo~ 提交于 2019-12-02 19:41:01
问题 I am trying to write a program where I can write data to an Access DB but I keep getting the error “Syntax error in INSERT INTO statement”. FirstLast is the name of the table; First and Last are columns in it. Imports System.Data.OleDb Public Class Form1 Dim theConnectionString As New OleDbConnection Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click theConnectionString.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C

Failed to update in msAccess but successfully in dgv C#

三世轮回 提交于 2019-12-02 16:40:13
问题 This is my code for btnUpdate so that msAccess will update. private void btnUpdate_Click(object sender, EventArgs e) { string CoString=(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=H:\AccessDatabase.accdb"); OleDbConnection con = new OleDbConnection(CoString); string Update ="Select * from StudentDb"; DataSet ds = new DataSet(); DataSet changes; OleDbCommandBuilder cbuild = new OleDbCommandBuilder(); try { con.Open(); OleDbDataAdapter da = new OleDbDataAdapter(Update, con); da.Fill(ds);

Error: Number of query values and destination fields are not the same

人走茶凉 提交于 2019-12-02 14:55:29
Public Class RoomInfo Dim ValTx As String Dim ValNr As Integer Private Sub cboRoomType_DropDown(sender As System.Object, e As System.EventArgs) Handles cboRoomType.DropDown cboRoomType.Items.Clear() qry = "select RoomType from tblRoomType" cmd = New OleDb.OleDbCommand(qry, con) dr = cmd.ExecuteReader While dr.Read cboRoomType.Items.Add(dr("RoomType")) End While End Sub Private Sub cboRoomType_SelectValueChanged(sender As Object, e As System.EventArgs) Handles cboRoomType.SelectedValueChanged ValTx = cboRoomType.Text qry = "select RoomType from tblRoomType where RoomType = '" & ValTx & "'" cmd

SELECT @@IDENTITY in Access always returning 0

非 Y 不嫁゛ 提交于 2019-12-02 14:06:48
问题 I have been trying to find a solution to this problem but so far nothing worked. private void Insert() { string ConnectionStringAccess = Provider=Microsoft.ACE.OLEDB.12.0;Data Source=###Jet OLEDB:Database Password=###; string query2 = "Select @@Identity"; int id = -1; string Query = "INSERT INTO tblTable (EmpNo, Name) VALUES (132, 'TestName');"; OleDbConnection con = new OleDbConnection(ConnectionStringAccess); OleDbCommand cmd = new OleDbCommand(Query, con); try { con.Open(); if (cmd

Problems reading in an Excel file in C#

一笑奈何 提交于 2019-12-02 13:10:16
问题 I'm reading an Excel file with OLDB Connection using this code var connectionString = string.Format("Provider=Microsoft.Jet.OLEDB.4.0; data source={0}; Extended Properties=Excel 8.0;", fileName); var fileName = string.Format("{0}\\s23.xls", Directory.GetCurrentDirectory()); var adapter = new OleDbDataAdapter("SELECT * FROM [TEJ3$] ", connectionString); DataTable dt=new DataTable(); adapter.Fill(dt, "Table1"); and after runing this code my data table is filled. But I have a column that has

oledb connection exception

泪湿孤枕 提交于 2019-12-02 13:05:15
This is my code string connectionString = @"Provider=SQLOLEDB;Data Source=Machine Name;Initial Catalog=MyTestDatabase;"; OleDbConnection conn = new OleDbConnection(connectionString); DataTable result = new DataTable(); try { conn.Open(); OleDbCommand cmd = new OleDbCommand("get_holidays", conn); cmd.CommandType = CommandType.StoredProcedure; OleDbDataAdapter adapter = new OleDbDataAdapter(cmd); adapter.Fill(result); } $exception {"Invalid authorization specification"} is thrown during conn.open(). Connection string format: Server=myServerAddress;Database=myDataBase;User ID=myUsername;Password

SQL Server Compact Edition 3.5 gives “Multiple-step operation generated errors” error for simple query

北战南征 提交于 2019-12-02 12:29:43
问题 I'm using a SQL Server CE database via Microsoft's OLEDB 3.5 SQL CE Driver. Here's my connection string: Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=C:\Users\me\Desktop\test1.sdf This query works fine: SELECT Thing FROM OtherThing WHERE name = 'TextThing' This query fails: SELECT Foo FROM Stuff And this is the error I get: Multiple-step operation generated errors. Check each status value. The only structural difference in the table themselves is that one has a text primary key and

Issue in updating MS Access records using oledbcommand.executeNonQuery(), result not updating

China☆狼群 提交于 2019-12-02 12:18:02
问题 I am posting a query first time here, So, Please ignore my formatting. I am trying to update my .accdb file using update command, but result of oledbcommand.executeNonQuery() is 0 hence result is not updating in the database. Though I am receiving no errors. Here is what I am doing. string vsql = string.Format("UPDATE DefTask_List SET [Action]=@Action WHERE [SNo]=@SNo"); vcom.Parameters.AddWithValue("@SNo", row.Cells[0].Value.ToString()); vcom.Parameters.AddWithValue("@Action", comboBox1.Text