delete data on sql server

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

Page 1 of 1

1 Replies - 7984 Views - Last Post: 03 June 2008 - 05:52 AM Rate Topic: -----

#1 gabanxx  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-June 08

delete data on sql server

Posted 02 June 2008 - 08:41 PM

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.


   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: 02 June 2008 - 08:47 PM


Is This A Good Question/Topic? 0
  • +

Replies To: delete data on sql server

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: delete data on sql server

Posted 03 June 2008 - 05:52 AM

Change this line


Dim varAdapter As SqlDataAdapter




To read like this


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 :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1