|
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
|
|
|
|
|
Add before update?
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Is that a question or a suggestion?
M.
|
|
|
|
|
Suggestion but untested one. The ? absolves me of responsibility for it not working :p
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Hi Ennis:
I tried your suggestion. Now the lower part of my code block looks like this:
<br />
dr["HomePage"] = "";<br />
dataSet_Suppliers.Tables[0].Rows.Add( dr );<br />
oleDbDataAdapter_Suppliers.Update( dataSet_Suppliers );<br />
dr.AcceptChanges();<br />
The call to "Update" now throws an OleDbException.
Thanks for your help anyway. If you have any other thoughts, I'm all ears...
Mark
|
|
|
|
|
move accept up one line. BTW, what are the specifics of the exception.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
try the following code...
DataRowView NewRow = DataSet.Tables[TableName].DefaultView.AddNew()
NewRow[ColumnName] = "";
NewRow.EndEdit();
DataAdapter.Update(DataSet, TableName);
bahaa
|
|
|
|
|
OK, so my code now looks like this:
<br />
DataRowView drv = dataSet_Suppliers.Tables[0].DefaultView.AddNew();<br />
drv["SupplierID"] = System.DBNull.Value;<br />
... more field assignments here ...<br />
drv["HomePage"] = "";<br />
drv.EndEdit();<br />
oleDbDataAdapter_Suppliers.Update( dataSet_Suppliers, "Suppliers" );<br />
When I call the "Update" command, an OleDbException is thrown.
Any other thoughts?
Mark
|
|
|
|
|
What the OleDbException message say...?
|
|
|
|
|
Hi Friend,
I want to build some controls for web.
Where to start?
I have built some controls for windows using visual studio but not for web.
Like i want to make a colour chooser which I want to run on web pages.?
Any help will be appriciated.
thanks
Naveed Kamboh
|
|
|
|
|
|
|
I try to use the Win32 function "LogonUser". But I always get "false".
I add a user in windows "myuser" and the password is "mypassword". The domain is "mydomain".
Then I use it like this :
LogonUser("myuser", "mydomain", "mypassword", LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref token);
But the return value is always false.
Are there any possibilities to check if user and password is ok ?
|
|
|
|
|
|
Thanks for the link.
Have you ever tried that function before ?
I'm trying it using:
Username = ""
Password = ""
Domain = ""
And..the return value is TRUE...
That means user is valid.
|
|
|
|
|
This means that the current user who is logged in is already logged in - imagine that!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I am using fingerprint reader.
Need help to capture the image in my application from fingerprint reader.
What's the mechanism used to capture image in fingerprint reader. Does it scans the image?
|
|
|
|
|
You'll need the SDK from the manufacturer of the Fingerprint Reader. Without it, you're not going to get anywhere.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
Cool. I had thought about trying something with my reader but didn't know where to start.
only two letters away from being an asset
|
|
|
|
|
Hi,
I am trying to use C# to execute the following procedure.
call RESOURCE_DEVELOPMENT.PHILIPS_REPORTS.ConfirmUDFExists('COM_X');
The error is:
ORA-12154: TNS:could not resolve service name
This is the c# code that I am using.
please note that the above procedure works fine in oracle.
objConn = DatabaseConnection.GetConnection(objContext);
objConn.Open();
objCmd = new OracleCommand(strSQL, objConn);
objCmd.CommandText = strSQL;
objCmd.CommandType = CommandType.Text;
objCmd.ExecuteNonQuery();
|
|
|
|
|
Cross posting it in as many forums on code project as you can until some one gets onto you for cross posting.
(Update your TNS name file mine is stored: C:\oracle\Ora92\network\ADMIN\tnsnames.ora)
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Can you guys please give me some ideas how to print
the dataGridView.
Any Links or API calls or Sample code to do that
help.
Also if there are couple of ways doing please tell me
which is better and easier.
Thanks
Kal
|
|
|
|
|
|
What is the best way to populate a context menu with data from a DB when it is clicked on?
Basically I am trying to create a context menu from a notifyIcon and populate it with names & numbers when it is right clicked... I can get the data from the DB, I just need to know how to put this data into the menu... Any ideas or pointers?
Thanks in advance,
Phil
|
|
|
|