Click here to Skip to main content
15,924,507 members
Home / Discussions / C#
   

C#

 
AnswerRe: Data Display dilemma Pin
led mike10-Aug-06 9:11
led mike10-Aug-06 9:11 
GeneralRe: Data Display dilemma Pin
sykiemikey10-Aug-06 17:41
sykiemikey10-Aug-06 17:41 
GeneralRe: Data Display dilemma Pin
led mike11-Aug-06 6:26
led mike11-Aug-06 6:26 
GeneralRe: Data Display dilemma Pin
sykiemikey11-Aug-06 13:32
sykiemikey11-Aug-06 13:32 
GeneralSolution Pin
sykiemikey12-Aug-06 1:18
sykiemikey12-Aug-06 1:18 
QuestionQuestion about DataGridView event sequence.... Pin
LongRange.Shooter10-Aug-06 8:14
LongRange.Shooter10-Aug-06 8:14 
AnswerRe: Question about DataGridView event sequence.... Pin
led mike10-Aug-06 9:07
led mike10-Aug-06 9:07 
QuestionNeed Help with Database Update using DataAdaptor Pin
Jethro6310-Aug-06 5:31
Jethro6310-Aug-06 5:31 
Greetings:

I am working my way through the MCSD "Developing Windows Based Apps" book. I'm in the section on databases and ADO. This chapter is woefully lacking in working examples so I am trying to contrive my own in order to see some of this stuff in action. To do this, I am connecting to the Northwind database supplied with Access in order to have a database to play with.

OK, so I have successfully connected to Northwind, I have used data readers and data adaptors to load tables from Northwind into data sets. I have successfully displayed the data using data grids. I have also successfully executed non querys, scalars and readers. Eveything is going tickety-boo.

However, the last thing on my agenda before moving on is to ADD a row to one of the tables and then actually write it back to the Northwind database file. To do this, I have fashioned a simple input form and when I get all the required input fields, I return from the form and execute the following:

		<br />
private void btnAddSupplier_Click(object sender, System.EventArgs e)<br />
{<br />
	AddSupplier	frmAdd = new AddSupplier();<br />
	frmAdd.ShowDialog( this );<br />
<br />
	if (frmAdd.AddSelected == false)<br />
		return;<br />
<br />
	oleDbDataAdapter_Suppliers.Fill( dataSet_Suppliers );<br />
<br />
	DataRow dr = dataSet_Suppliers.Tables[0].NewRow();<br />
	dr["SupplierID"] = System.DBNull.Value;<br />
	dr["CompanyName"] = frmAdd.CompanyName;<br />
	dr["ContactName"] = frmAdd.ContactName;<br />
	dr["ContactTitle"] = frmAdd.ContactTitle;<br />
	dr["Address"] = frmAdd.Address;<br />
	dr["Region"] = frmAdd.City;<br />
	dr["City"] = frmAdd.RegionProv;<br />
	dr["PostalCode"] = frmAdd.Postal;<br />
	dr["Country"] = frmAdd.Country;<br />
	dr["Phone"] = "";<br />
	dr["FAX"] = "";<br />
	dr["HomePage"] = "";<br />
<br />
	oleDbDataAdapter_Suppliers.Update( dataSet_Suppliers );<br />
	dataSet_Suppliers.Tables[0].Rows.Add( dr );<br />
	dr.AcceptChanges();<br />
}<br />


"dataSet_Suppliers" and "oleDbDataAdaptor_Suppliers" are both members of the main form that I am using for my experimentation scaffold. I am certain that the adaptor and data set are successfully loaded with the Supplier table. I am able to Fill the supplier data set through the data adaptor and bind the data set to a data grid and display it.

The problem is that the above code does not write the new row to the database file. It appears unchanged. The code executes OK, but the changes are not applied to the file. I am confused about the order in which I should call "AcceptChanges" for the DataRow and "Update" for the data adaptor. The MCSD book says that you must call "Update" on the data adaptor FIRST. I don't quite get why this is so but I have fooled around with the order and it doesn't make any difference. There is no change to the database file.

I am obviously a novice so I am assuming that I am missing a step somewhere. Any help would be appreciated.
Thank you,
Mark
AnswerRe: Need Help with Database Update using DataAdaptor Pin
Ennis Ray Lynch, Jr.10-Aug-06 5:52
Ennis Ray Lynch, Jr.10-Aug-06 5:52 
GeneralRe: Need Help with Database Update using DataAdaptor Pin
Jethro6310-Aug-06 5:58
Jethro6310-Aug-06 5:58 
GeneralRe: Need Help with Database Update using DataAdaptor Pin
Ennis Ray Lynch, Jr.10-Aug-06 6:00
Ennis Ray Lynch, Jr.10-Aug-06 6:00 
GeneralRe: Need Help with Database Update using DataAdaptor Pin
Jethro6310-Aug-06 7:31
Jethro6310-Aug-06 7:31 
GeneralRe: Need Help with Database Update using DataAdaptor Pin
Ennis Ray Lynch, Jr.10-Aug-06 8:19
Ennis Ray Lynch, Jr.10-Aug-06 8:19 
AnswerRe: Need Help with Database Update using DataAdaptor Pin
bahaa_sa510-Aug-06 5:59
bahaa_sa510-Aug-06 5:59 
GeneralRe: Need Help with Database Update using DataAdaptor Pin
Jethro6310-Aug-06 7:24
Jethro6310-Aug-06 7:24 
GeneralRe: Need Help with Database Update using DataAdaptor Pin
bahaa_sa512-Aug-06 21:34
bahaa_sa512-Aug-06 21:34 
Questionbuilding cotrols for web Pin
Naveed Kamboh10-Aug-06 5:26
Naveed Kamboh10-Aug-06 5:26 
AnswerRe: building cotrols for web Pin
Judah Gabriel Himango10-Aug-06 11:46
sponsorJudah Gabriel Himango10-Aug-06 11:46 
GeneralRe: building cotrols for web Pin
Naveed Kamboh10-Aug-06 22:28
Naveed Kamboh10-Aug-06 22:28 
QuestionChecking logon user Pin
stancrm10-Aug-06 4:48
stancrm10-Aug-06 4:48 
AnswerRe: Checking logon user Pin
Dave Kreskowiak10-Aug-06 5:30
mveDave Kreskowiak10-Aug-06 5:30 
GeneralRe: Checking logon user Pin
stancrm10-Aug-06 7:53
stancrm10-Aug-06 7:53 
GeneralRe: Checking logon user Pin
Dave Kreskowiak10-Aug-06 9:21
mveDave Kreskowiak10-Aug-06 9:21 
Questioncapturing image in Fingerprint reader Pin
SwathiKotikalapudi10-Aug-06 4:47
SwathiKotikalapudi10-Aug-06 4:47 
AnswerRe: capturing image in Fingerprint reader Pin
Dave Kreskowiak10-Aug-06 5:27
mveDave Kreskowiak10-Aug-06 5:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.