Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - database wont update

Reply
 
Old 06-27-2008   #1 (permalink)
D


 
 

database wont update

D wrote:
Quote:

> I am trying to add records to a database and getting no errors but the
> databse is not updated.
> Not sure what is wrong maybe in my function I'm losing some thing?
> What do you think? My code is below.
>
<snip>
Quote:

> OdbcConnection dbconn = new
> OdbcConnection("Provider=MSDASQL.1;DRIVER={Microsoft Access Driver
> (*.mdb)};DBQ=c:\\hedgefunds\\db1.mdb;DATABASE=db1;UID=root;PWD=;
> OPTION=1;");
Your problem's right there: you're using Access. Use a real database
instead. SQL Server Express is free. So's SQL Server Compact Edition if you
need the ability to exchange databases as files. Snarking aside, though...
Quote:

> public void UpdateinDB(DbDataAdapter dbrs, DataSet dbADOrs,
> String[] fields)
> {
> DataTable dt = dbADOrs.Tables[0];
> DataRow rec = dt.NewRow();
> MessageBox.Show(dt.Columns[0].ToString());
> if (fields[0] != "fundname")//file has header so ignore it.
> {
> rec["name"] = fields[0];
> rec["date"] = fields[1];
> rec["corr"] = fields[2];
>
> try
> {
> dbrs.Update(dbADOrs);//no update to the database occurs
> here no exceptions triggered
You forgot to call .AddRow(). This always trips up newcomers (I speak from
experience), but .NewRow() doesn't actually add a new row to the table, it
just creates one based on the table's scheme.

See http://msdn.microsoft.com/library/z16c79x4 for a sample.

--
J.

My System SpecsSystem Spec
Old 06-27-2008   #2 (permalink)
Jeroen Mostert


 
 

Re: database wont update

D wrote:
Quote:

> I am trying to add records to a database and getting no errors but the
> databse is not updated.
> Not sure what is wrong maybe in my function I'm losing some thing?
> What do you think? My code is below.
>
<snip>
Quote:

> OdbcConnection dbconn = new
> OdbcConnection("Provider=MSDASQL.1;DRIVER={Microsoft Access Driver
> (*.mdb)};DBQ=c:\\hedgefunds\\db1.mdb;DATABASE=db1;UID=root;PWD=;
> OPTION=1;");
Your problem's right there: you're using Access. Use a real database
instead. SQL Server Express is free. So's SQL Server Compact Edition if you
need the ability to exchange databases as files. Snarking aside, though...
Quote:

> public void UpdateinDB(DbDataAdapter dbrs, DataSet dbADOrs,
> String[] fields)
> {
> DataTable dt = dbADOrs.Tables[0];
> DataRow rec = dt.NewRow();
> MessageBox.Show(dt.Columns[0].ToString());
> if (fields[0] != "fundname")//file has header so ignore it.
> {
> rec["name"] = fields[0];
> rec["date"] = fields[1];
> rec["corr"] = fields[2];
>
> try
> {
> dbrs.Update(dbADOrs);//no update to the database occurs
> here no exceptions triggered
You forgot to call .AddRow(). This always trips up newcomers (I speak from
experience), but .NewRow() doesn't actually add a new row to the table, it
just creates one based on the table's scheme.

See http://msdn.microsoft.com/library/z16c79x4 for a sample.

--
J.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
My Vista Wont update Vista security
Windows wont update! Limewire, BitComet wont connect!! Network & Sharing
Works database 2007 and Office database 2003 .NET General
Windows Update Wont Update! Vista General
How long is it going to take MS to update their database so that the weather gadget works? Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46