After user enters a row of data into a DataGrid (.net 1.1), how to auto-update the actual database?

S

sherifffruitfly

Hi all,

I've got a form with a datagrid defined & presented to the user at
runtime (code at the bottom.) With this, the user can happily enter
all the data she likes. After a row of data is entered in the
datagrid, and the datagrid is about to start a new row for the user,
I'd like an UpdateDatabase(DataRow rowJustEntered) to be called.

I suppose some kind of define-and-subscribe-to-some-event has to take
place, but that's precisely the sort of thing I don't understand so
well.

How can I do this? I'm imagining the database update routine to be
centered around an InsertCommand.ExecuteNonQuery() call.

Thanks for any help,

cdj

==========================

//manualForm is a Form with a DataGrid on it,
//and has already been instantiated.
DataSet manualDataSet = new DataSet();
manualDataSet.Tables.Add("table");
manualForm.dataGrid.SetDataBinding(manualDataSet, "table");
manualForm.Width = 300;
manualForm.StartPosition = FormStartPosition.CenterScreen;

DataTable theTable = manualDataSet.Tables["table"];

DataColumn colIndex = new DataColumn("index",
System.Type.GetType("System.Int32"));
DataColumn colDate = new DataColumn("date",
System.Type.GetType("System.DateTime"));
DataColumn colData = new DataColumn("data",
System.Type.GetType("System.Double"));

theTable.Columns.Add(colIndex);
theTable.Columns.Add(colDate);
theTable.Columns.Add(colData);

colIndex.AllowDBNull = false;
colDate.AllowDBNull = false;
colData.AllowDBNull = false;

DataColumn[] keyCols = {colIndex, colDate};
theTable.PrimaryKey = keyCols;

manualForm.dataGrid.ColumnHeadersVisible = true;

manualForm.Show();
 
S

sherifffruitfly

Hi all,

I've got a form with a datagrid defined & presented to the user at
runtime (code at the bottom.) With this, the user can happily enter
all the data she likes. After a row of data is entered in the
datagrid, and the datagrid is about to start a new row for the user,
I'd like an UpdateDatabase(DataRow rowJustEntered) to be called.

I suppose some kind of define-and-subscribe-to-some-event has to take
place, but that's precisely the sort of thing I don't understand so
well.

Nevermind. lol! Woohoo! Figured one out on my own!

manualDataSet.Tables["table"].RowChanging += new
DataRowChangeEventHandler(UpdateManual);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top