By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,152 Members | 1,414 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,152 IT Pros & Developers. It's quick & easy.

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

P: n/a
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();

Jan 30 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Jan 30, 2:54 pm, "sherifffruitfly" <sherifffruit...@gmail.com>
wrote:
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);

Jan 31 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.