| | |
Updating and writing to Access Database in C#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 1
Reputation:
Solved Threads: 0
I have looked through the forum for this information. But I did not find anything I could use in my little program.
I have this read code:
------------------------------------------------------------------
Now I need two codes to do the following:
Look through the entry “if (oleDataReader.GetString(0) == "John")” and if there is a match I need to overwrite the information:
oleDataReader.GetString(0) = ”Something New”
oleDataReader.GetString(1) = ”Something New”
oleDataReader.GetString(2) = ”Something New”
oleDataReader.GetString(3) = ”Something New”
I know that i should not use GetString but some thing like WriteString!
I also need a code to go to the end of the data and inset these information:
oleDataReader.GetString(0) = ”Something New”
oleDataReader.GetString(1) = ”Something New”
oleDataReader.GetString(2) = ”Something New”
oleDataReader.GetString(3) = ”Something New”
I know that i should not use GetString but some thing like WriteString!
I hope there is someone that could give med some code to look at. I am new at this and I am taking classes in C#, but I am working on a little projekt of my own!
I have this read code:
C# Syntax (Toggle Plain Text)
---------------------------------------------------------------------- using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.OleDb; namespace AddressBook { class Program { static void Main(string[] args) { //Opret forbindelse til databasen. OleDbConnection oleConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=adresse_opslag.mdb"); //Opret objekt og sql søgning. OleDbCommand oleCommand = new OleDbCommand("SELECT * FROM adresse_opslag", oleConnection); try { //Åben database forbindelsen oleConnection.Open(); //Opret "Datareader" som skal læse i tabelen. OleDbDataReader oleDataReader = oleCommand.ExecuteReader(); //"While loop" som skal søge hele data tabelen igennem. //"Console" som skal byttes ud med Windowsform!. while (oleDataReader.Read()) { // Søge funktionen "Søgeord" if (oleDataReader.GetString(0) == "John") { Console.WriteLine(oleDataReader.GetString(0) + "\t" + oleDataReader.GetString(1) + "\t" + oleDataReader.GetString(2) + "\t" + oleDataReader.GetString(3)); } } //Luk forbindelsen. oleConnection.Close(); //Hold console åben. Denne linje skal bare slettes. Console.Read(); } //Visning af fejl hvis den opstår. catch (OleDbException ex) { Console.WriteLine(ex.Message); Console.Read(); } } } }
Now I need two codes to do the following:
Look through the entry “if (oleDataReader.GetString(0) == "John")” and if there is a match I need to overwrite the information:
oleDataReader.GetString(0) = ”Something New”
oleDataReader.GetString(1) = ”Something New”
oleDataReader.GetString(2) = ”Something New”
oleDataReader.GetString(3) = ”Something New”
I know that i should not use GetString but some thing like WriteString!
I also need a code to go to the end of the data and inset these information:
oleDataReader.GetString(0) = ”Something New”
oleDataReader.GetString(1) = ”Something New”
oleDataReader.GetString(2) = ”Something New”
oleDataReader.GetString(3) = ”Something New”
I know that i should not use GetString but some thing like WriteString!
I hope there is someone that could give med some code to look at. I am new at this and I am taking classes in C#, but I am working on a little projekt of my own!
Last edited by cscgal; Sep 6th, 2008 at 7:09 pm. Reason: Added code tags
•
•
Join Date: May 2004
Posts: 95
Reputation:
Solved Threads: 10
You can't update the database using
There's more than one way to do this. Here's one:
This approach only requires you to write the
See also the
OleDbDataReader or any other DbDataReader subclass. They provide forward-only, read-only access to data. You need something else.There's more than one way to do this. Here's one:
- Create an
OleDbDataAdapterusing yourSELECTstatement. - Create a
OleDbCommandBuilderfrom your adapter. - Set the adapter's
UpdateCommandproperty using the command builder'sGetUpdateCommandmethod. - Use the adapter to fill a
DataTablewith your data. - Modify the contents of the table's rows.
- Call the adapter's
Updatemethod to commit changes in the database.
This approach only requires you to write the
SELECT statement; follow the links for more information on how to use these classes.See also the
System.Data.OleDb and System.Data namespace documentation. --smg
![]() |
Similar Threads
- Inserting,deleting,updating and editing records to a MS Access database (C#)
- ASP.NET & VB.NET --- Need to have work as a Freelancer . (Post your Resume)
- Writing to an Access Database (Visual Basic 4 / 5 / 6)
- General Tips for Mac OS X (Mac tips 'n' tweaks)
Other Threads in the C# Forum
- Previous Thread: Can't find C# DirectX reference: UtilityToolKit
- Next Thread: how to create toolbar button with combobox in WPF
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox class client color combobox control conversion csharp custom database datagridview dataset datetime degrees development draganddrop drawing encryption enum excel file files form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator oracle path photoshop picturebox post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





