P
Pavils Jurjans
Hello,
Here's my code:
static string DbConnStr = "*OLEDB conn str*";
static DataSet LoadDataSet(string sqlQuery)
{
DataSet dataset = new DataSet();
return LoadDataSet(dataset, sqlQuery);
}
static DataSet LoadDataSet(DataSet dataset, string sqlQuery)
{
OleDbDataAdapter adapter = new OleDbDataAdapter(sqlQuery, DbConnStr);
adapter.Fill(dataset);
return dataset;
}
public static void Main()
{
DataSet mySet = LoadDataSet("SELECT * FROM myTable");
foreach (DataRow dataRow in mySet.Tables[0].Rows)
{
Console.WriteLine("\t{0}\t{1}", dataRow["id"], dataRow["txt"]);
if (dataRow["id"] + "" == "2") {
Console.WriteLine("Attempting to update...");
dataRow.BeginEdit();
dataRow["txt"] = dataRow["txt"] + "#";
dataRow.EndEdit();
}
}
mySet.Tables[0].AcceptChanges();
}
I certainly do something wrong here, because I fail to updat the real data
in the database. Please, tell me what's the problem with my code... I know
that I can always build some SQL statement thatt updates the data, when
executed, but I want to find out the possiblities of ADO.NET built-in
features.
Thanks,
Pavils
Here's my code:
static string DbConnStr = "*OLEDB conn str*";
static DataSet LoadDataSet(string sqlQuery)
{
DataSet dataset = new DataSet();
return LoadDataSet(dataset, sqlQuery);
}
static DataSet LoadDataSet(DataSet dataset, string sqlQuery)
{
OleDbDataAdapter adapter = new OleDbDataAdapter(sqlQuery, DbConnStr);
adapter.Fill(dataset);
return dataset;
}
public static void Main()
{
DataSet mySet = LoadDataSet("SELECT * FROM myTable");
foreach (DataRow dataRow in mySet.Tables[0].Rows)
{
Console.WriteLine("\t{0}\t{1}", dataRow["id"], dataRow["txt"]);
if (dataRow["id"] + "" == "2") {
Console.WriteLine("Attempting to update...");
dataRow.BeginEdit();
dataRow["txt"] = dataRow["txt"] + "#";
dataRow.EndEdit();
}
}
mySet.Tables[0].AcceptChanges();
}
I certainly do something wrong here, because I fail to updat the real data
in the database. Please, tell me what's the problem with my code... I know
that I can always build some SQL statement thatt updates the data, when
executed, but I want to find out the possiblities of ADO.NET built-in
features.
Thanks,
Pavils