473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Delete row from database using OleDb

maylortaylor
72 64KB
I have this function working half right. The part that is working right is where I can select a row on the DataGridView, call this function using a "Delete Row" button, and then it will delete the row from the DataGridView....However, it does not delete the row on the database.

Can anyone help me with deleting the row from the DB using OleDb?

Expand|Select|Wrap|Line Numbers
  1. Function DeleteTableRow()
  2.         Dim TaxConnStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ConfigurationManager.AppSettings("Database")
  3.         Dim dbConnection = New OleDbConnection(TaxConnStr)
  4.  
  5.         Try
  6.             Dim dbCommand As OleDbCommand = New OleDbCommand
  7.             Dim rdr2 As OleDbDataReader
  8.  
  9.             Dim selectedRow = DataGridView1.SelectedRows
  10.  
  11.             dbCommand.CommandText = "DELETE FROM UserCriteria WHERE RowID =" & selectedRow
  12.             If dbConnection.State = ConnectionState.Closed Then
  13.                 dbConnection.Open()
  14.             End If
  15.  
  16.             dbCommand.Connection = dbConnection
  17.             rdr2 = dbCommand.ExecuteReader
  18.             dbCommand.ExecuteNonQuery()
  19.  
  20.  
  21.             rdr2.Close()
  22.  
  23.                        '''allows you to select on cell in the row to delete entire row
  24.             For Each oneCell As DataGridViewCell In DataGridView1.SelectedCells
  25.                 If oneCell.Selected Then
  26.                     DataGridView1.Rows.RemoveAt(oneCell.RowIndex)
  27.                 End If
  28.             Next
  29.  
  30.  
  31.  
  32.         Catch ex As Exception
  33.             MsgBox(ex.Message)
  34.         Finally
  35.             dbConnection.Close()
  36.         End Try
  37.     End Function
Mar 27 '13 #1
4 6590
Rabbit
12,516 Expert Mod 8TB
Your database table has a field called RowID that is populated the same way as the DataGridView?
Mar 27 '13 #2
maylortaylor
72 64KB
Well the row in the database is called "ID" and that particular row on the DataGridView is set to hidden.
Mar 27 '13 #3
Rabbit
12,516 Expert Mod 8TB
The row? You mean the field in the table in the database? If it's named ID, then you need to use ID in your SQL, not RowID.
Mar 27 '13 #4
check this datagridview tutorial

http://csharp.net-informations.com/d...w-tutorial.htm

pringston
May 10 '13 #5

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

Similar topics

4
by: NS | last post by:
Hi, I am trying to execute a prepare statement using oledb provider for DB2. The command.Prepare() statement is giving me an exception " No error information available:...
1
by: Azel | last post by:
Hi, I am trying to learn ADO.net and I keep running into problems trying to insert data into my Access Database: data.mdb. here is my code: <code> // Database Variables
9
by: Peter | last post by:
Hello£¬everyone, My program will collect a testing machine's data ,save the data and deal with the data everyday. I want to use vb.net to create database, add and delete tables or modify the...
1
by: spicyz | last post by:
I'm receiving an exception when my webmethod exits after opening/closing an Access database. I can reproduce this easily enough by creating a new default ASP .NET Web Service in VS.NET 2003. ...
0
by: genojoe | last post by:
I have a 4 column, 6 row Excel sheet with all cells formatted for text: 1 1 a a 2 2 b b 3 3 c c a 4 d 1 b 5 e 2 c 6 f 3 I have the following schema.ini:
6
by: yc022 | last post by:
Hi all, this is my first time using this so i'm not really sure how it works. please bear with me. i am trying to delete a row in a database using a select list. First of all i have a query to...
0
by: DeepthiSem | last post by:
Hi Everyone I have an issue while saving .rpt file into DB2 database using C# windows application. The provider i have used is OLEDB provider. It is not supporting to insert large amount of data...
1
by: =?Utf-8?B?U2hlZXMgQWJpZGk=?= | last post by:
I read an article on the link: http://support.microsoft.com/default.aspx?scid=kb;en-us;306572 related to reading data from Excel using OLEDB The topic's heading is: How to query and display excel...
2
by: mnarewec | last post by:
I would like to execute multiple SQL Statement using OleDB command but its coming up with error " Characters found after end of statement" Below is my pieces of code. Public Class DalOleDb...
2
by: vasanth chandrasekaran | last post by:
Hai All, I try to insert the Dataset value in Exiting excel file by using OLEDB provider.But i face error messagge in objCmd.ExecuteNonQuery(); The error is :Syntax error in INSERT...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.