Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,934 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,574 people online right now. Registration is fast and FREE... Join Now!




delete data on sql server

 
Reply to this topicStart new topic

delete data on sql server, delete data on my textbox that are stored in sql server 2000

gabanxx
2 Jun, 2008 - 07:41 PM
Post #1

New D.I.C Head
*

Joined: 2 Jun, 2008
Posts: 1

i create a form that can save data in sql..now i want to delete the data that appear in the text box that i'have created earlier...the problem is the data wont be deleted...i tryto fix the error but it wont do anygood can u guys help me with this prob....this is the error mistake that appear...

line that the error occur- 'varAdapter.DeleteCommand = varCommand'
An unhandled exception of type 'System.NullReferenceException' occurred in ROP1.exe

Additional information: Object reference not set to an instance of an object.


CODE
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim varAdapter As SqlDataAdapter

        If MessageBox.Show("Do you really want to delete this record?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = DialogResult.No Then
            MsgBox("Operation cancelled")
            Exit Sub
        End If
        varConnection = New SqlConnection("Server=(local);user id=sa;password=;Initial Catalog=ROP1") 'STEP 1
        varConnection.Open() 'STEP 2

        varQuery = "DELETE FROM tbl_rop WHERE Name_User ='" & Trim(TextBox1.Text) & "', Date_of_birth= '" & Trim(TextBox2.Text) & "' , Hobbies='" & Trim(TextBox3.Text) & "' , Phone_Number ='" & Trim(TextBox4.Text) & "' where Name_User = '" & Trim(TextBox1.Text) & "'" 'STEP 3
        varCommand = New SqlCommand(varQuery, varConnection)
        varAdapter.DeleteCommand = varCommand
        varAdapter.UpdateCommand = varUpdateCommand
        varCommand.ExecuteNonQuery()

        varCommand.Dispose() 'STEP 6
        varConnection.Close() 'STEP 7
        varAdapter.Update(varDataSet)

      

    End Sub


This post has been edited by gabanxx: 2 Jun, 2008 - 07:47 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Delete Data On Sql Server
3 Jun, 2008 - 04:52 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Change this line


vb

Dim varAdapter As SqlDataAdapter



To read like this


vb

Dim varAdapter As New SqlDataAdapter()



Until you tell the compiler that varAdapter is a New SqlDataAdapter it really doesn't exist, thus the NullReferenceException. Hope that helps smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 03:47PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month