Vb.net Source code to execute SQL Query
Execute SQL Command with single function Public Function ExecuteSQLQuery(ByVal SQLQueryString As String) As Boolean
Dim err As Boolean = True
Dim SqlConn As New SqlClient.SqlConnection
Dim Sqlcmmd As New SqlClient.SqlCommand
Try
SqlConn.ConnectionString = ConnectionStrinG
SqlConn.Open()
Sqlcmmd.Connection = SqlConn
Sqlcmmd.CommandText = SQLQueryString
Sqlcmmd.CommandType = CommandType.Text
Sqlcmmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
err = False
Finally
SqlConn.Close()
SqlConn.Dispose()
Sqlcmmd.Connection = Nothing
End Try
Return err
End Function
Example to execute commands
ExecuteSQLQuery("DELETE FROM Students where studentid=20")
ExecuteSQLQuery("INSERT INTO STUDENTS (COL1,COL2,COL3) VALUES ('JYOTHI','SURESH','DIRECTOR')")
No comments:
Post a Comment