Question:

I cant delete data using VB from SQL. My database is in SQL.Please help.

by Guest61468  |  earlier

0 LIKES UnLike

Dim cnnstr As String

cnnstr = "Provider=SQLOLEDB;" & _

"Data Source=ABC\SQLEXPRESS;" & _

"Initial Catalog= XYZ;" & _

"Integrated Security=SSPI;" & _

"uid=;pwd=;"

Dim myConnection As OleDbConnection = New OleDbConnection(cnnstr)

myConnection.Open()

Dim SQLStr As String

SQLStr = "delete from Customers where CNAME= '" & CustomerNameTextBox.Text & "' , CPHONE='" & MobileTextBox.Text & "' , CTABLE='" & TableTextBox.Text & "' , CDATE='" & DateTextBox.Text & "' , CTIME= '" & TimeTextBox.Text & "'"

Dim myCmd As New OleDbCommand

myCmd.Connection = myConnection

myCmd.CommandText = SQLStr

myCmd.CommandType = CommandType.Text

Try

myCmd.ExecuteNonQuery()

MessageBox.Show("Customer account deleted")

Catch ex As Exception

MessageBox.Show("err msg")

myConnection.Close()

End Try

End Sub

 Tags:

   Report

1 ANSWERS


  1. The problem is your SQL:

    delete from tablename

    where col1 = a and col2 = b and col3 = c

    You were missing the "and"

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.