sql commands in visual basic express 2005
hi im trying to use a delete command to delete data from table1 if its in table2
my command is
delete table1 from table1, table2 where table1.test = table2.test
please help
i keep getting
delete is not declared so i tryed this
Dim
deleteAsNew SqlCommand()
delete table1 from table1, table2 where table1.test = table2.test
now i get delete isnt an expression please help
willing to change anything to get this to work
Hi,
your delete-statement is wrong. The syntax is:
| DELETE FROM table_name WHERE column_name = some_value |
from
http://www.w3schools.com/sql/sql_delete.aspthis page (http://www.w3schools.com/sql) may be very helpful, when learning sql.
What exactly do you need only the sql statemen or some lines of VB code?
Please tell us what you want to delete in your tables, if you need further assistance.
Hi Justin ,
The Sql-command is: "Delete FROM table1 where (searchcondtion................"
If you are deleting based on values from another table:
"Delete From Table1 where test IN (SELECT Test FROM Table2);"
By that you are taking all the values in Table2.field("Test") and If they also are in Table1.field("Test"), you delete them in Table1.
Hope it helps
try this link: MSDN SqlCommand.ExecuteNonQuery
In your on_click button event add this code
-
Dim strCnn As String = "Your Connection String"
Dim strSQL as String = "Delete From Server where Server IN (SELECT Product1 FROM Customer)"
CreateCommand(strCnn, strCnn)
-Then add this sub (copied from the link above)
Public Sub CreateCommand(ByVal queryString As String, ByVal connectionString As String)
Using connection As New SqlConnection(connectionString)
Dim command As New SqlCommand(queryString, connection)
command.Connection.Open()
command.ExecuteNonQuery()
End Using
End SubAlso add:
Imports System.Data.SqlClient
To the top of your .vb file
SMB at 2007-9-8 >

check this out:
http://support.microsoft.com/?kbid=823679-- from the link --
Version 1.1 of SqlClient introduced a regression in the handling of connection strings that contain apostrophes (') or double quotation marks (""). This causes connection strings with correctly escaped apostrophes or double quotation marks to fail, and you receive the following error message:
Format of the initialization string does not conform to specification starting at index {0}.
SMB at 2007-9-8 >
