473,395 Members | 1,474 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Add new record to database

I am trying to add new record in database. There is no compile error but
program is not adding any record to database. Hot to fix it? This is my
code:

OleDbDataAdapter odbAdapt;
DataSet dsObject= new DataSet();
DataTable dtObject;
string SQL;
string ConnStr;
int BrojSlogova;

ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;data source=c:/dbase/Proba.mdb";
SQL = "SELECT * FROM Names"
OleDbConnection odbconn = new OleDbConnection();
odbconn.ConnectionString = ConnStr;
odbconn.Open();
odbAdapt = new OleDbDataAdapter (SQL, ConnStr);
dsObject = new DataSet();
odbAdapt.Fill(dsObject);
dtObject = dsObject.Tables[0];

// Then add new record

DataRow WorkRow;
WorkRow= dtObject.NewRow();
WorkRow["FirstName"] = "George";
WorkRow["LastName"] = "Bush";
dtObject.Rows.Add(WorkRow);

This doesn't work!

Nov 29 '06 #1
1 2526
Firstly, if you don't have an insert method set in the DataAdapter, you
won't be able to use the DataAdapter to update (meaning insert, update or
delete) the db.
Secondly, when you add a row to a datatable, you only add it to the
datatable object which is a memory representation of relationnal datas (not
specific to a platform). You have to use the Update method of the
DataAdapter and passed the modified datatable in order to apply updates to
the DB.
Thirdly, since .Net 2.0, TableAdapters are more accurates than DataAdapters.

In order to help understanding ADO.Net concepts (especially disconnect
working), I suggest you to follow this tutorial which is a very good one :
http://www.asp.net/learn/dataaccess/....aspx?tabid=63

Hope that helps

"Marko" <ma********@marko.coma écrit dans le message de news:
ek**********@sunce.iskon.hr...
>I am trying to add new record in database. There is no compile error but
program is not adding any record to database. Hot to fix it? This is my
code:

OleDbDataAdapter odbAdapt;
DataSet dsObject= new DataSet();
DataTable dtObject;
string SQL;
string ConnStr;
int BrojSlogova;

ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;data
source=c:/dbase/Proba.mdb";
SQL = "SELECT * FROM Names"
OleDbConnection odbconn = new OleDbConnection();
odbconn.ConnectionString = ConnStr;
odbconn.Open();
odbAdapt = new OleDbDataAdapter (SQL, ConnStr);
dsObject = new DataSet();
odbAdapt.Fill(dsObject);
dtObject = dsObject.Tables[0];

// Then add new record

DataRow WorkRow;
WorkRow= dtObject.NewRow();
WorkRow["FirstName"] = "George";
WorkRow["LastName"] = "Bush";
dtObject.Rows.Add(WorkRow);

This doesn't work!



Nov 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: yvan | last post by:
Approximately once a month, a client of ours sends us a bunch of comma-delimited text files which I have to clean up and then import into their MS SQL database. All last week, I was using a Cold...
6
by: DebbieG | last post by:
I have created a database for a client and was told that it was to be a one-user database. Well, you know the next statement ... now they want 3 people to be able to use the database. (FYI, I...
15
by: Steve | last post by:
I have a form with about 25 fields. In the BeforeUpdate event of the form, I have code that sets the default value of each field to its current value. For a new record, I can put the focus in any...
2
by: RC | last post by:
I am getting the following error message. "Write Conflict this record has been changed by another user since you started edting it. If you save the record, you will overwrite the changes...." I...
1
by: Scott269 | last post by:
So I've got an old MS Works database I imported into Access. I needed a primary key so I created a record number field that was just the record number I manually inserted when I entered it in the...
3
by: domcatanzarite | last post by:
How would one create a button that on click advances the form to the next "non recurring record" as opposed to the next record. The field the button needs to que from has groups of duplicate...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
10
by: MLH | last post by:
Suppose, in a multi-user environment, you have append query SQL in a VBA procedure that looks like INSERT INTO MyTable... and the next line reads MyVar=DMax("","MyTable... You can never be...
3
by: smugcool | last post by:
Hi, I have created a form in Visual basic 6.0 for adding/updating the change request made by various users. Well i am able to update the record through my code in access database. Can anyone...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.