M
Marcus Olsson
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
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