473,804 Members | 2,962 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL Database update from C# console application

I'm stuck. I have created a console application that does its job of
collecting the data I want it to however I am stuck on writing this data back
to a database. All of the examples I have been able to find on using the
SQLConnectin, SQLDataAdapter and DataSet objects all point me to a forms
application where you can visually modify the data the send the
update,insert,d elete commands. I have not been able to locate how to update
or insert data on a DataSet that is not bound to a visual object of some kind.

Thanks for any assistance...

FYI... I am attempting this with VS2005 Beta 2 and SQL 2005 AprilCTP.

Thanks!

Nov 17 '05 #1
4 10620
You reference the values directly...

ie
DataSetName.Tab les[TableIndexOrNam e].Rows[RowIndex].Columns[ColumnIndexOrNa me]
= WhateverValue;

"James" <Ja***@discussi ons.microsoft.c om> wrote in message
news:2E******** *************** ***********@mic rosoft.com...
I'm stuck. I have created a console application that does its job of
collecting the data I want it to however I am stuck on writing this data
back
to a database. All of the examples I have been able to find on using the
SQLConnectin, SQLDataAdapter and DataSet objects all point me to a forms
application where you can visually modify the data the send the
update,insert,d elete commands. I have not been able to locate how to
update
or insert data on a DataSet that is not bound to a visual object of some
kind.

Thanks for any assistance...

FYI... I am attempting this with VS2005 Beta 2 and SQL 2005 AprilCTP.

Thanks!

Nov 17 '05 #2
okay, let me make sure I am on the right track...

I can call the fill method to load the dataset from the database, compare my
discovered data with the data in the dataset by directly refrencing the
fields as you said, then call the update method to send the updated data back
to the database.

If I need to insert a new row of data do I just call an Add method to the
dataset and reference the table name?

"W.G. Ryan MVP" wrote:
You reference the values directly...

ie
DataSetName.Tab les[TableIndexOrNam e].Rows[RowIndex].Columns[ColumnIndexOrNa me]
= WhateverValue;

"James" <Ja***@discussi ons.microsoft.c om> wrote in message
news:2E******** *************** ***********@mic rosoft.com...
I'm stuck. I have created a console application that does its job of
collecting the data I want it to however I am stuck on writing this data
back
to a database. All of the examples I have been able to find on using the
SQLConnectin, SQLDataAdapter and DataSet objects all point me to a forms
application where you can visually modify the data the send the
update,insert,d elete commands. I have not been able to locate how to
update
or insert data on a DataSet that is not bound to a visual object of some
kind.

Thanks for any assistance...

FYI... I am attempting this with VS2005 Beta 2 and SQL 2005 AprilCTP.

Thanks!


Nov 17 '05 #3
James wrote:
I'm stuck. I have created a console application that does its job of
collecting the data I want it to however I am stuck on writing this data back
to a database. All of the examples I have been able to find on using the
SQLConnectin, SQLDataAdapter and DataSet objects all point me to a forms
application where you can visually modify the data the send the
update,insert,d elete commands. I have not been able to locate how to update
or insert data on a DataSet that is not bound to a visual object of some kind.

Thanks for any assistance...


I think this is what your after. Below is a code snippet that updates
two databases, one via ODBC and another via OLE. Hope this helps.
oleDbConnection 1 = new System.Data.Ole Db.OleDbConnect ion();
odbcConnection1 = new System.Data.Odb c.OdbcConnectio n();

oleDbConnection 1.ConnectionStr ing = @"Jet OLEDB:Global Partial Bulk
Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet
OLEDB:Database Password=;Data Source=""C:\Doc uments and Settings\All
Users\Documents \DATA.mdb"";Pas sword=;Jet OLEDB:Engine Type=5;Jet
OLEDB:Global Bulk
Transactions=1; Provider=""Micr osoft.Jet.OLEDB .4.0"";Jet OLEDB:System
database=;Jet OLEDB:SFP=False ;Extended Properties=;Mod e=Share Deny
None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System
Database=False; Jet OLEDB:Don't Copy Locale on Compact=False;J et
OLEDB:Compact Without Replica Repair=False;Us er ID=Admin;Jet
OLEDB:Encrypt Database=False" ;

odbcConnection1 .ConnectionStri ng =
"STMT=;OPTION=5 24292;DSN=Looe; UID=XXXX;PASSWO RD=XXXX;SOCKET= ;DESC=;DATABASE =YYYY;SERV"
+ "ER=192.168.0.7 ;PORT=3306";

oleDbConnection 1.Open();
odbcConnection1 .Open();

OleDbCommand odc = oleDbConnection 1.CreateCommand ();
odc.CommandText = "UPDATE........ .";
odc.ExecuteNonQ uery();

OdbcCommand oc = odbcConnection1 .CreateCommand( );
oc.CommandText = "UPDATE........ ....";
oc.ExecuteNonQu ery();

oc.Close();
odc.Close();


Cheers
Jimbo
Nov 17 '05 #4

"James" <Ja***@discussi ons.microsoft.c om> wrote in message
news:6B******** *************** ***********@mic rosoft.com...
okay, let me make sure I am on the right track...

I can call the fill method to load the dataset from the database, compare
my
discovered data with the data in the dataset by directly refrencing the
fields as you said, then call the update method to send the updated data
back
to the database. Yes
If I need to insert a new row of data do I just call an Add method to the
dataset and reference the table name?
Yes
"W.G. Ryan MVP" wrote:
You reference the values directly...

ie
DataSetName.Tab les[TableIndexOrNam e].Rows[RowIndex].Columns[ColumnIndexOrNa me]
= WhateverValue;

"James" <Ja***@discussi ons.microsoft.c om> wrote in message
news:2E******** *************** ***********@mic rosoft.com...
> I'm stuck. I have created a console application that does its job of
> collecting the data I want it to however I am stuck on writing this
> data
> back
> to a database. All of the examples I have been able to find on using
> the
> SQLConnectin, SQLDataAdapter and DataSet objects all point me to a
> forms
> application where you can visually modify the data the send the
> update,insert,d elete commands. I have not been able to locate how to
> update
> or insert data on a DataSet that is not bound to a visual object of
> some
> kind.
>
> Thanks for any assistance...
>
>
>
> FYI... I am attempting this with VS2005 Beta 2 and SQL 2005 AprilCTP.
>
> Thanks!
>


Nov 17 '05 #5

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

Similar topics

7
2330
by: Job Lot | last post by:
How can I terminate console application in Try…Catch…Finally…End Try block so that code in Finally gets executed. If I use End statement Finally does not get executed. Following is my code written in Console Application. Module Module1 Sub Main() Call Testing()
2
10986
by: Chris | last post by:
Hi, Currently, I have a console application written in C# and an unmanaged legacy DLL written in VC++ 6.0. In the DLL's previous application, when an event occurs in the DLL, a windows message would be sent to the host GUI application via PostMessage to WM_USER + X. The GUI application would then execute a function to retrieve data from the DLL. With this new setup, I have a console application as the host. I retrieved the handle...
5
11261
by: Barry Mossman | last post by:
Hi, can I detect whether my class is running within the context of a Console application, vs say a WinForm's application ? also does anyone know whether the compiler or runtime is smart enough to avoid the overhead of writing to the console if it is not visible, eg I am running inside a WinForm application. thanks
2
7911
by: krukinews | last post by:
Hi, I'm trying to write small program (console application) that reads from Event Log end writes data to SQL Server. I'm new to C# and ADO.NET and for last 3 days I have read many tutorials and I think that I understand basic (only basic) concepts of ADO.NET. But I simple can't create console application that uses Master Detail concept. Table structure (keys only).
3
15031
by: inpreet | last post by:
I am trying to build a console application in C#.Net. This application is suppose to run in background without user interaction. How can I hide console to appear?
1
1235
by: gustavoadt | last post by:
Hello! I have a console application that works with a SQL Database. And I have some basic questions: Console.WriteLine("City name: "); this = Console.ReadLine(); It compiles. But doesn't stop for me to write the city name. Why? What's the other way?
1
25637
by: Claudia Fong | last post by:
Hello I'm trying to connect to a sql database using C# console application but I'm having trouble to connect.. can someone help me? // Create an empty SqlConnection object. using (SqlConnection con = new SqlConnection()) { // Configure the SqlConnection object's connection string.
5
2085
by: Claudia Fong | last post by:
Hi, I'm using console application to connect to a db and I managed to use the SELECT statement to display records in my DB but I also need to UPDATE some fields in my table but after I run the code below, it didn't update the record.. Can someone tell me? Cheers
3
1850
by: cmrhema | last post by:
Hello I have written the following in console application. My problem is I want the application running in the back. and it should check every thirty minutes and update thedatabase the problem is that the threading does not work and to make the application run every thirty minutes am i suppose to create a windows service. Please let me know Thanks
0
9704
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
9571
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
10318
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...
0
10069
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...
1
7608
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.