By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,876 Members | 1,291 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,876 IT Pros & Developers. It's quick & easy.

SQL Database update from C# console application

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.