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

Using SQL statements in C# >NET

P: 1
I have tried to use the "DELETE" statement to delete a row from the table, which satisfies part_number not equal to EA*. But this part is not working.


OleDbDataAdapter MyAdapterBasic = new OleDbDataAdapter("SELECT part_id, part_number, description FROM parts;DELETE FROM parts WHERE part_number LIKE 'EA%'", MyConnection);


I have used two SQL statements seperated by ; symbol.
Is there any best way to do this.

Error: An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

Please help...
Apr 26 '07 #1
Share this Question
Share on Google+
2 Replies


P: 37
Hi,

usage of DataAdapter in C# 2005

//Instantiate DataAdapter.
The below statements instantiate the DataAdapter objects. We need to instantiate the DataAdapters one each for the data we retrieve and data we update.
Expand|Select|Wrap|Line Numbers
  1. myAccountAdapter = new SqlDataAdapter(str_Account_Select, myConnection);
  2. myAllAccountAdapter = new SqlDataAdapter(str_Allaccount_Select, myConnection);
  3.  
  4. //Setting the DataAdapter command properties.
  5.  
  6. The DataAdapter class has four properties:
  7.  
  8. 1.    SelectCommand
  9. 2.    InsertCommand
  10. 3.    UpdateCommand
  11. 4.    DeleteCommand
  12.  
  13. Each of the property perform a specific operation on a database. Listed below are the four properties and their purpose.
  14.  
  15. 1.    SelectCommand
  16. This read-write property returns or sets the SQL statement that will be used when rows are selected/retrieved from the data source.
  17.  
  18. 2.    InsertCommand.
  19. This read-write property returns or sets the SQL statement that will be used when rows are inserted in to the data source.
  20.  
  21. 3.    UpdateCommand
  22. This read-write property returns or sets the SQL statement that will be used when rows are updated in the data source.
  23.  
  24. 4.    DeleteCommand.
  25. This read-write property returns or sets the SQL statement that will be used when rows are deleted  from the data source.
  26.  
  27. When the DataAdapter needs to retrieve or send data to and from the database, it uses Command objects which must be specified. We specify the command objects for selecting, updating, and deleting rows in the database.  This is done by creating command objects, and then assigning them to the appropriate DataAdapter property: SelectCommand, InsertCommand, UpdateCommand, and DeleteCommand are shown below.
  28.  
  29. //Set DataAdapter Command properties
  30. myAccountAdapter.SelectCommand = comAccountSelect;
  31. myAllAccountAdapter.SelectCommand = comAllAccountSelect;
  32. myAccountAdapter.InsertCommand = comAccountInsert;
  33. myAccountAdapter.DeleteCommand = comAccountDelete;
  34. myAccountAdapter.UpdateCommand = comAccountUpdate;
  35.  
  36. //Add Delete Command parameters.
  37. comAccountDelete.Parameters.Add("@id", SqlDbType.Char, 6, "AccountCode");
  38.  
[Link Removed]
Apr 27 '07 #2

Frinavale
Expert Mod 5K+
P: 9,731
Bhar,

You are a great resource to the forum and have been extremely helpful in providing comprehensive and detailed answers to people's questions; especially in concerns to .NET. Your help is greatly appreciated.

Please refrain from including links to advertisements as this is against forum rules.
Please review the FAQ Forum for posting rules.
This link contains information concerning were it is acceptable to post these types of links.

Thanks,

MODERATOR
Apr 27 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.