473,563 Members | 2,884 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Delete row from database using OleDb

maylortaylor
72 New Member
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 6642
Rabbit
12,516 Recognized Expert Moderator MVP
Your database table has a field called RowID that is populated the same way as the DataGridView?
Mar 27 '13 #2
maylortaylor
72 New Member
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 Recognized Expert Moderator MVP
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
pringstonmali
1 New Member
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
7792
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: DB_E_NOCOMMAND(0x80040E0C)." My code is very simple and is working with other oledb provider, like SQL Server and oracle.
1
4122
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
8271
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 records in the database. Is it possible to create a SQL Server database using vb.net? I know I can use vb.net and ADOX to create a Access database....
1
2097
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. Adding this code to the default HelloWorld() webmethod will cause the problem. String* sConnection = S"Provider=Microsoft.Jet.OLEDB.4.0;User...
0
2029
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
2287
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 produce what i would like to be held in the select (dropdown) list. i then create the select list with a delete button. I then try to create the...
0
2317
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 i.e(.rpt) file into the BLOB feild of DB2 database. Can any one of you provide a help in solving this issue. Regards
1
10395
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 data by using ASP.NET, ADO.NET, and Visual C# .NET I am trying with the same code in Visual Studio 2005 in ASP.NET application. The code i am using...
2
12869
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 Public Class DalOleDb Private _dss As DataSet Private _daa As OleDbDataAdapter Private _cnn As OleDbConnection
2
4933
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 INTO statement.
0
7583
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7948
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6250
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5484
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5213
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.