Update typed dataset
The following code is a class in a project where I try to use a typed dataset. I have used the same class with MS-SQL, and I thought it would be possible to reuse the code, just replacing the sqlclient with MySQLClient.
This is my code:
using System;
using System.Web.UI;
using MySql.Data.MySqlClient;
using System.Data;
namespace project
{
public class DataPage : Page
{
protected string[] TableNames = {"nn", "nnn"};
protected string ConnectionString = "Data Source=;Database=;User ID=;Password=;";
protected dsTypedDataSet TypedDataSet;
public DataPage()
{
this.Init += new System.EventHandler(this.HentData);
}
public void GetData(object o, EventArgs e)
{
if (Application["TypedDataset"] == null)
{
TypedDataSet = new dsTypedDataSet();
foreach(string TableName in TableNames)
{
MySqlDataAdapter Adapter = GetAdapter(TableName);
Adapter.Fill(TypedDataSet, TableName);
}
Application["TypedDataSet"] = TypedDataSet;
}
else
TypedDataSet = (DataSet)Application["TypedDataSet"];
}
public void UpdateData()
{
if (Application["TypedDataSet"] == null)
GetData(null,null);
foreach (string TableName in TableNames)
{
MySqlDataAdapter Adapter = GetAdapter(TableName);
Adapter.Update(TypedDataSet, TableName);
}
}
public MySqlDataAdapter GetAdapter(string TableName)
{
if (Application["Adapter" + TableName] == null)
{
MySqlDataAdapter Adapter = new MySqlDataAdapter("SELECT * FROM " + TableName, ConnectionString);
MySqlCommandBuilder cmdBuilder = new MySqlCommandBuilder(Adapter);
Application["Adapter" + TableName] = Adapter;
}
return (MySqlDataAdapter) Application["Adapter" + TableName];
}
}
}
I call the UpdateData() from my webform, but when it tries to call the Adapter.Update, I get an System.InvalidOperationException: Connection must be valid and open.
I am certain that my connectionstring is valid, and I have no problems with reading data from the database and dataset.
I've also tried using a System.Data.DataSet, but I get the same error.
Any ideas?
Subject
Written By
Posted
Update typed dataset
January 10, 2005 07:02AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.