VB.NET

Moderators: seancampbell
Number of threads: 4022
Number of posts: 10035

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
deleting a record based on name from aceess db Posted by mashalyy on 25 Jul 2012 at 6:06 AM
Hi.
I want to delete a particular record based on name from access database in vb.net

db name: stpl
table name: equipments
field: Mandal, sal, Date
eg: Pune, 2000, 23/7/12
chennai, 1200, 11/5/12


If i want to delete pune from my record, I just want to press delete button, it should pop-up msgbox asking me to enter Mandal name, And when i enter mandal name: pune, then it shud check with the db whether the record exists, if yes then shud delete it otherwise it shud say:"no record exists".

My code is: here I used textbox, actually i want to use pop-up box.
Iam getting error: object ref set not to instance of an object.


Try
Mycn.Open()
Dim command As String
command = "delete from Equipments where Mandal='" & txtMan.Text & "';"
myDA.DeleteCommand.CommandText = command
myDA.DeleteCommand.ExecuteNonQuery()
MessageBox.Show("Record deleted")
Catch ex As Exception
MessageBox.Show("no record")
Finally
Mycn.Close()
End Try

I tried this code also:

Try
Mycn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & System.Environment.CurrentDirectory & "\STPL.accdb")
Dim sql As String
sql = "Delete from Equipments where Mandal=" & Convert.ToString(txtMan.Text) & ""
Mycn.Open()
command = New OleDbCommand(sql, Mycn)
command.ExecuteNonQuery()
MessageBox.Show("Record Deleted Successfully", "Deleting Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Mycn.Close()
command.Dispose()
ClearTextBox(Me)
txtMan.Focus()
Catch ex As OleDbException
MessageBox.Show("Please enter Name only", "Deleting Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error)
txtMan.Focus()
Catch ex As Exception
MessageBox.Show("Please enter Name only", "Deleting Employee Details", MessageBoxButtons.OK, MessageBoxIcon.Error)

txtMan.Focus()
End Try

But no use.........
help me out





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.