473,326 Members | 2,076 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,326 software developers and data experts.

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,delete 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 10602
You reference the values directly...

ie
DataSetName.Tables[TableIndexOrName].Rows[RowIndex].Columns[ColumnIndexOrName]
= WhateverValue;

"James" <Ja***@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.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,delete 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.Tables[TableIndexOrName].Rows[RowIndex].Columns[ColumnIndexOrName]
= WhateverValue;

"James" <Ja***@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.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,delete 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,delete 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.
oleDbConnection1 = new System.Data.OleDb.OleDbConnection();
odbcConnection1 = new System.Data.Odbc.OdbcConnection();

oleDbConnection1.ConnectionString = @"Jet OLEDB:Global Partial Bulk
Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet
OLEDB:Database Password=;Data Source=""C:\Documents and Settings\All
Users\Documents\DATA.mdb"";Password=;Jet OLEDB:Engine Type=5;Jet
OLEDB:Global Bulk
Transactions=1;Provider=""Microsoft.Jet.OLEDB.4.0" ";Jet OLEDB:System
database=;Jet OLEDB:SFP=False;Extended Properties=;Mode=Share Deny
None;Jet OLEDB:New Database Password=;Jet OLEDB:Create System
Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet
OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet
OLEDB:Encrypt Database=False";

odbcConnection1.ConnectionString =
"STMT=;OPTION=524292;DSN=Looe;UID=XXXX;PASSWORD=XX XX;SOCKET=;DESC=;DATABASE=YYYY;SERV"
+ "ER=192.168.0.7;PORT=3306";

oleDbConnection1.Open();
odbcConnection1.Open();

OleDbCommand odc = oleDbConnection1.CreateCommand();
odc.CommandText = "UPDATE.........";
odc.ExecuteNonQuery();

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

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


Cheers
Jimbo
Nov 17 '05 #4

"James" <Ja***@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.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.Tables[TableIndexOrName].Rows[RowIndex].Columns[ColumnIndexOrName]
= WhateverValue;

"James" <Ja***@discussions.microsoft.com> wrote in message
news:2E**********************************@microsof t.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,delete 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
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...
2
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...
5
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...
2
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...
3
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
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...
1
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...
5
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...
3
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.