473,769 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

database wont update

D
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.

Thanks

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows. Forms;
using System.Data.Com mon;
using System.Data.Odb c;
using System.Collecti ons;
using System.IO;
namespace WindowsFormsApp lication1
{
public partial class Form1 : Form
{
public Form1()
{
OdbcConnection dbconn = new
OdbcConnection( "Provider=MSDAS QL.1;DRIVER={Mi crosoft Access Driver
(*.mdb)};DBQ=c: \\hedgefunds\\d b1.mdb;DATABASE =db1;UID=root;P WD=;
OPTION=1;");
dbconn.Open();
OdbcDataAdapter dbrs = new OdbcDataAdapter ("Select * From
MyTable;", dbconn);
OdbcCommandBuil der builder = new OdbcCommandBuil der(dbrs);
DataSet dbADOrs = new DataSet();

InitializeCompo nent();
dbrs.MissingSch emaAction = MissingSchemaAc tion.AddWithKey ;
dbrs.Fill(dbADO rs);
OpenReturnFile( dbrs, dbADOrs);
}
public void OpenReturnFile( DbDataAdapter dbrs, DataSet dbADOrs)
{
StreamReader sfp;
sfp = File.OpenText(" c:\\temp\\updat enewfile.txt");
string buffer;
string[] fields;
char[] delims={'\t'};
while (sfp.EndOfStrea m == false)
{
buffer = sfp.ReadLine();
fields=buffer.S plit(delims,
StringSplitOpti ons.RemoveEmpty Entries);
UpdateinDB(dbrs , dbADOrs, fields);

}

}
public void UpdateinDB(DbDa taAdapter 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(dbA DOrs);//no update to the database occurs
here no exceptions triggered
}
catch (Exception e)
{
StreamWriter fout = new
StreamWriter("c :\\temp\\status .txt", true);
fout.WriteLine( "Error at " + fields[0].ToString()+ "
" + e.InnerExceptio n.ToString());
fout.Close();
}
}
}
}

}

Jun 27 '08 #1
1 1239
D wrote:
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>
OdbcConnection dbconn = new
OdbcConnection( "Provider=MSDAS QL.1;DRIVER={Mi crosoft Access Driver
(*.mdb)};DBQ=c: \\hedgefunds\\d b1.mdb;DATABASE =db1;UID=root;P WD=;
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...
public void UpdateinDB(DbDa taAdapter 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(dbA DOrs);//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.
Jun 27 '08 #2

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

Similar topics

25
4388
by: cory | last post by:
Hi, I have an Access database and am having an ASP.NEt application written for it. It is almost complete. I have a hosting company that I signed up with a month ago but before I did anything I asked them if Access and ASP.NET would work on their servers, they said yes so I bought in. Now they are saying my application wont work on their servers using MSaccess and I can only use SQL or asp 3.0. They are saying Microsoft is trying to...
6
1729
by: Brett | last post by:
Not sure what the problem is here... Trying to update from a datagrid to an access database using vb.net... Its not updating the database but Im not getting any errors... Here is my code... 'OleDbUpdateCommand1 Me.OleDbUpdateCommand1.CommandText = "UPDATE tblGifts SET gift = ?, name = ?, purchased = ? WHERE (autonum = ?) AND (gi" & _ "ft = ? OR ? IS NULL AND gift IS NULL) AND (name = ? OR ? IS NULL AND name IS NUL" & _
25
2787
by: Mark Harrison | last post by:
I would like to try and build a queuing mechanism on top of Postgresql. Imagine an application where a large number of processes generate images and queue up thumbnail requests. A smaller number of processes (running on a dedicated set of machines) generate thumbnails for those images. Adding entries to the queue from multiple processes is easy, by executing statements such as: insert into nameq(action,name) values('add','foo');
2
4173
by: TJ | last post by:
Hi All, I am having some trouble. I have created a database via the new database option inside VWD2005. Then and table or two. I have been able to perform INSERT and SELECT operations on the table, BUT cannot do an UPDATE. After the update command it says 1 row updated, but the data does not change. At one point I receieved a message stating something like (heavily paraphrased...):
1
3498
by: eduardoben | last post by:
I use a tableadapter with the sql string = select * fom table where field=? I load the desired record in a form and populate textboxes but after i modify them when i use tableadapter.update it wont save the changes to the database i get the error "There is no valid update command" any ideas? Thanks
2
989
by: umeshpotdar | last post by:
hi frdz i want to do synchronization of database the thing is like that, i have two databases which is deve. in sql server 2005 (both are same) suppose one is at Delhi and another is at Mumbai. i want such a facility which can update the database of Delhi automatically when change has been made in db of Mumbai . it wont be frequently update the db, it will be once in the day.
2
1176
by: Bomac8 | last post by:
I have a stored procedure: CREATE PROCEDURE ( @residentID int OUTPUT, @resNames (100), @LName (100), @resAddress (50), @resEMail (50), @resPhone (50),
1
1631
by: =?Utf-8?B?UmljaA==?= | last post by:
Private Sub UpdateTblHistory() Dim strSql As String strSql = "Update tbl_History set SubscrID = @SubscrID Where ID = @ID" da.UpdateCommand.CommandText = strSql da.UpdateCommand.Parameters.Add("@SubscrID", SqlDbType.VarChar, 50, "SubscrID") da.UpdateCommand.Parameters.Add("@ID", SqlDbType.Int, 4, "ID") da.Update(ds, "tbl_History")
30
5716
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the database I have a table with Date/time column. The database is located on a machine that is set to dd/mm/yyyy also. When I enter date 7/1/08 (as in January 7, 2008), it stores it in the database as 1/7/08 instead of 7/1/08. Why is it like that...
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.