HighTechTalks DotNet Forums  

add row ODBC ADO.NET

Dotnet Framework (ODBC.net) microsoft.public.dotnet.framework.odbcnet


Discuss add row ODBC ADO.NET in the Dotnet Framework (ODBC.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Marcus Olsson
 
Posts: n/a

Default add row ODBC ADO.NET - 09-01-2003 , 11:42 AM






. Reply (E-mail) Forward (E-mail)

Subject: Add row, ODBC and ADO.NET
From: "Marcus Olsson" <nospam (AT) nospam (DOT) se> Sent:
9/1/2003 8:08:17 AM




Hi!

I have a beginner problem and hope that someone easily
can solve my problem.

I want to connect to my Access database with ODBC. I have
downloaded MS ODBC library for connection with ODBC
from .NET.

It looks like I get the data and able to add the row, but
when I should update the source with the new data it
doesn't work.

Can you please give me a good link or tell me what's
wrong below.

Please help!

Code:

// Create a SQL statement
string mySelectQuery = "SELECT * FROM Bokning";

// ... a connection string
string sConnString = "Dsn=Bokning_new";

OdbcConnection oODBCConnection = new OdbcConnection();
oODBCConnection.ConnectionString = sConnString;

oODBCConnection.Open();

// Create a command object
OdbcCommand myOdbcCommand = new OdbcCommand
(mySelectQuery , oODBCConnection);

// Create an adapter, initialized with the command object
OdbcDataAdapter da = new OdbcDataAdapter(myOdbcCommand);

// Create a dataset
DataSet ds = new DataSet("bokning_new"); // Name could be
whatever

// Fill the DataSet with data from the database
da.Fill(ds);

DataTable myTable = ds.Tables[0];
//DataTable myTable = ds.Tables(0);

DataRow newRow = myTable.NewRow();
newRow["Date"] = DateTime.Today.ToShortDateString();

myTable.Rows.Add(newRow);

da.Update(ds);

// Close connection
oODBCConnection.Close();







Regards,
/Marcus
..



Reply With Quote
  #2  
Old   
Chris W.
 
Posts: n/a

Default Re: add row ODBC ADO.NET - 09-02-2003 , 01:56 AM






On Mon, 1 Sep 2003 08:42:41 -0700, "Marcus Olsson" <nospam (AT) nospam (DOT) se>
wrote:

Quote:
. Reply (E-mail) Forward (E-mail)

Subject: Add row, ODBC and ADO.NET
From: "Marcus Olsson" <nospam (AT) nospam (DOT) se> Sent:
9/1/2003 8:08:17 AM




Hi!

I have a beginner problem and hope that someone easily
can solve my problem.

I want to connect to my Access database with ODBC. I have
downloaded MS ODBC library for connection with ODBC
from .NET.

It looks like I get the data and able to add the row, but
when I should update the source with the new data it
doesn't work.

Can you please give me a good link or tell me what's
wrong below.

Please help!
[snip]

Take a look at the OdbcCommandBuilder Class in the ODBC.NET help file.
Here is the sample code from that page.

Chris
--------------
Public Function SelectOdbcSrvRows(myDataSet As DataSet,myConnection As _
String, mySelectQuery As String, myTableName As String) As DataSet

Dim myConn As New OdbcConnection(myConnection)
Dim myDataAdapter As New OdbcDataAdapter()
myDataAdapter.SelectCommand = New OdbcCommand(mySelectQuery, myConn)

' ** You're missing this next line **
Dim custCB As OdbcCommandBuilder = New OdbcCommandBuilder(myDataAdapter)

myConn.Open()

Dim custDS As DataSet = New DataSet
myDataAdapter.Fill(custDS, "Customers")

' Code to modify data in DataSet here

' Without the OdbcCommandBuilder this line would fail.
myDataAdapter.Update(custDS, "Customers")

myConn.Close()

SelectOdbcSrvRows = custDS
End Function 'SelectOdbcSrvRows


Reply With Quote
  #3  
Old   
Yuriy B. Belyaev
 
Posts: n/a

Default Re: add row ODBC ADO.NET - 10-03-2003 , 06:30 AM



Hil.

And I have very interesting problem.

I install ODBC for NET, but ditective Imports System.Data..... do not view
odbc library.


"Chris W." <GuamChris (AT) No (DOT) Spam.Yahoo.Com> wrote

Quote:
On Mon, 1 Sep 2003 08:42:41 -0700, "Marcus Olsson" <nospam (AT) nospam (DOT) se
wrote:

. Reply (E-mail) Forward (E-mail)

Subject: Add row, ODBC and ADO.NET
From: "Marcus Olsson" <nospam (AT) nospam (DOT) se> Sent:
9/1/2003 8:08:17 AM




Hi!

I have a beginner problem and hope that someone easily
can solve my problem.

I want to connect to my Access database with ODBC. I have
downloaded MS ODBC library for connection with ODBC
from .NET.

It looks like I get the data and able to add the row, but
when I should update the source with the new data it
doesn't work.

Can you please give me a good link or tell me what's
wrong below.

Please help!
[snip]

Take a look at the OdbcCommandBuilder Class in the ODBC.NET help file.
Here is the sample code from that page.

Chris
--------------
Public Function SelectOdbcSrvRows(myDataSet As DataSet,myConnection As _
String, mySelectQuery As String, myTableName As String) As DataSet

Dim myConn As New OdbcConnection(myConnection)
Dim myDataAdapter As New OdbcDataAdapter()
myDataAdapter.SelectCommand = New OdbcCommand(mySelectQuery, myConn)

' ** You're missing this next line **
Dim custCB As OdbcCommandBuilder = New OdbcCommandBuilder(myDataAdapter)

myConn.Open()

Dim custDS As DataSet = New DataSet
myDataAdapter.Fill(custDS, "Customers")

' Code to modify data in DataSet here

' Without the OdbcCommandBuilder this line would fail.
myDataAdapter.Update(custDS, "Customers")

myConn.Close()

SelectOdbcSrvRows = custDS
End Function 'SelectOdbcSrvRows



Reply With Quote
  #4  
Old   
Bernie Yaeger
 
Posts: n/a

Default Re: add row ODBC ADO.NET - 10-04-2003 , 07:44 PM



Hi Yuriy,

You may have to browse for it when you set a reference to it.

HTH,

Bernie Yaeger
"Yuriy B. Belyaev" <jurijb (AT) mail (DOT) ru> wrote

Quote:
Hil.

And I have very interesting problem.

I install ODBC for NET, but ditective Imports System.Data..... do not view
odbc library.


"Chris W." <GuamChris (AT) No (DOT) Spam.Yahoo.Com> wrote in message
news:20c8lvs3chcdsv7si8to5t8csk8jkh3fkj (AT) 4ax (DOT) com...
On Mon, 1 Sep 2003 08:42:41 -0700, "Marcus Olsson" <nospam (AT) nospam (DOT) se
wrote:

. Reply (E-mail) Forward (E-mail)

Subject: Add row, ODBC and ADO.NET
From: "Marcus Olsson" <nospam (AT) nospam (DOT) se> Sent:
9/1/2003 8:08:17 AM




Hi!

I have a beginner problem and hope that someone easily
can solve my problem.

I want to connect to my Access database with ODBC. I have
downloaded MS ODBC library for connection with ODBC
from .NET.

It looks like I get the data and able to add the row, but
when I should update the source with the new data it
doesn't work.

Can you please give me a good link or tell me what's
wrong below.

Please help!
[snip]

Take a look at the OdbcCommandBuilder Class in the ODBC.NET help file.
Here is the sample code from that page.

Chris
--------------
Public Function SelectOdbcSrvRows(myDataSet As DataSet,myConnection As _
String, mySelectQuery As String, myTableName As String) As DataSet

Dim myConn As New OdbcConnection(myConnection)
Dim myDataAdapter As New OdbcDataAdapter()
myDataAdapter.SelectCommand = New OdbcCommand(mySelectQuery, myConn)

' ** You're missing this next line **
Dim custCB As OdbcCommandBuilder = New OdbcCommandBuilder(myDataAdapter)

myConn.Open()

Dim custDS As DataSet = New DataSet
myDataAdapter.Fill(custDS, "Customers")

' Code to modify data in DataSet here

' Without the OdbcCommandBuilder this line would fail.
myDataAdapter.Update(custDS, "Customers")

myConn.Close()

SelectOdbcSrvRows = custDS
End Function 'SelectOdbcSrvRows





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.