|
-
November 17th, 2011, 04:49 PM
#1
MDB <---> DataTable Fehler OleDbAdapterUpdate.Udate()
Ich wollte die Daten, welche ich aus einer MDB einlese und abändere wieder zurück in die Datenbank zu schreiben. Es funktioniert solange ich nicht versuche die Text Spalte abzuändern.
Error: Fehler in der Update Syntax
Was muss ich ändern?
----------------------------Code----------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
OleDbDataAdapter dAdapter;
OleDbCommandBuilder cBuilder;
DataSet dSet;
DataTable dTable;
string connString = @"Provider=Microsoft.ACE.OLEDB.12.0;Persist Security Info=False;Data Source=lookup.accdb;";
OleDbConnection conn = new OleDbConnection(connString);
string query = "SELECT * FROM Tabelle1";
dAdapter = new OleDbDataAdapter(query, conn);
cBuilder = new OleDbCommandBuilder(dAdapter);
dSet = new DataSet();
dAdapter.Fill(dSet, "Tabelle1");
dTable = new DataTable();
dTable = dSet.Tables["Tabelle1"];
Ausgabe(dTable);
/********************************
* DataTable: "Tabelle1"
* ID ¦ Lookup-Wert ¦ Text ¦
* ---+-------------+-----------+
* 1 ¦ 1 ¦ C# ¦
* 2 ¦ 1 ¦ F# ¦
* 3 ¦ 2 ¦ Apple ¦
* 4 ¦ 2 ¦ Microsoft ¦
* *****************************/
//Änderungen vornehmen
dTable.Rows[3][1] = 1; // --> (int) Funktioniert
dTable.Rows[3][2] = "Value"; // --> (string) Funktioniert nicht
dAdapter.UpdateCommand = cBuilder.GetUpdateCommand();
try
{
dAdapter.Update(dTable); //--> Funktioniert nicht
dAdapter.Update(dSet, "Tabelle1"); //--> Funktioniert nicht
}
catch (OleDbException ex)
{
Console.WriteLine(ex.Message);
}
Ausgabe(dTable);
}
private static void Ausgabe(DataTable dTable)
{
Console.WriteLine("\n============================= \n");
for (int i = 0; i < dTable.Rows.Count; i++)
{
Console.WriteLine(dTable.Rows[i][0] + "\t " + dTable.Rows[i][1] + "\t " + dTable.Rows[i][2]);
}
Console.WriteLine("\n============================= \n");
}
}
}
---------------------------- Code ----------------------------
-
November 17th, 2011, 05:18 PM
#2
Re: MDB <---> DataTable Fehler OleDbAdapterUpdate.Udate()
Vielleicht wenn Sie die Frage auf Englisch stellen würden, würde jemand verstehen und Ihnen helfen.
Developing using:
.NET3.5 / VS 2010
-
November 18th, 2011, 09:43 AM
#3
Re: MDB <---> DataTable Fehler OleDbAdapterUpdate.Udate()
I'm sorry. I forget about that.
I would like to put the records (which I read from a MDB and modify in the Code you see above) back into the MDB. Its works only when i just modify the columns containing a int value but not when I modify the column containing a string value. I have no idea what I have to do.
Any suggestions? Thank you all.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|