Can someone tell me what is wrong with this code?
#region Using directives
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using soForms;
#endregion
namespace Thai_Dictionary
{
partial class frmWords : MNLForm
{
OleDbConnection myConn;
OleDbDataAdapter myAdapter;
DataSet ds;
OleDbParameter workParam = null;
string myQuery = "select ID, Word from Thai";
public frmWords()
{
InitializeComponent();
ConnectToData(); // establish database connection and create DataSet
grdThaiWords.DataSource = ds.Tables[0].DefaultView;
//myGrid.SetDataBinding(ds, "CardTest");
DataTable t = ds.Tables[0];
t.RowChanged += new DataRowChangeEventHandler(Row_Changed);
}
private void Words_Load(object sender, EventArgs e)
{
}
public void ConnectToData()
{
ds = new DataSet();
myConn = new OleDbConnection(System.Configuration.ConfigurationSettings.ConnectionStrings["Dictionary"].ConnectionString);
myAdapter = new OleDbDataAdapter();
myAdapter.SelectCommand = new OleDbCommand(myQuery, myConn);
myAdapter.Fill(ds, "Thai");
insertCommand();
updateCommand();
}
public void updateCommand()
{
string updateQuery = "Update Thai Set Word = @Word WHERE ID = @ID";
myAdapter.UpdateCommand = new OleDbCommand(updateQuery, myConn);
workParam = myAdapter.UpdateCommand.Parameters.Add("@Word", OleDbType.Char);
workParam.SourceColumn = "Word";
workParam.SourceVersion = DataRowVersion.Current;
}
private void Row_Changed(object ob, DataRowChangeEventArgs e)
{
DataTable t = (DataTable)ob;
Console.WriteLine("RowChanged " + e.Action.ToString() + "\t" + e.Row.ItemArray[0]);
}
public void insertCommand()
{
string insertQuery = "Insert into Thai VALUES (@Word)";
myAdapter.InsertCommand = new OleDbCommand(insertQuery, myConn);
workParam = myAdapter.InsertCommand.Parameters.Add("@Word", OleDbType.Char);
workParam.SourceColumn = "Word";
workParam.SourceVersion = DataRowVersion.Current;
}
public void UpdateValue()
{
try
{
myAdapter.Update(ds, "CardTest");
Console.Write("Updating DataSet succeeded!");
}
catch (Exception e)
{
Console.Write(e.ToString());
}
}
}
}