|
|
|
|
|
Author:
|
ptaylor
|
|
Views:
|
3414
|
|
|
How to use SQL
|
|
|
How to use SQL statments in Visual Basic.NET
Read (SELECT) Write (INSERT, UPDATE, DELETE)
|
|
|
|
|
Imports System.Data.SqlClient Dim SQLStr As String Private ConnString As String connstring = "Data Source=myserver;Initial Catalog=databasename;Integrated Security=True" SQLStr = "SELECT * FROM tblQuestion" SQLStr = "INSERT into tblQuestion(Name, Question) VALUES('Fred', 'How to use SQL?')" SQLStr = "UPDATE tblQuestion SET Answer = 'Like this' Where Question = 'How to use SQL?'" SQLStr = "DELETE FROM tblQuestion WHERE Question ='How to use SQL?'" Dim SQLConn As New SqlConnection() Dim SQLCmd As New SqlCommand() SQLConn.ConnectionString = ConnString SQLConn.Open SQLCmd.Connection = SQLConn SQLCmd.CommandText = SQLStr SQLCmd.ExecuteNonQuery() SQLConn.Close() Dim SQLConn As New SqlConnection() Dim SQLCmd As New SqlCommand() Dim SQLdr As SqlDataReader SQLConn.ConnectionString = ConnString SQLConn.Open SQLCmd.Connection = SQLConn SQLCmd.CommandText = SQLStr SQLdr = SQLCmd.ExecuteReader Do While dr.Read() MsgBox(dr("Column Name")) End While Loop While SQLdr.NextResult() SQLdr.Close SQLConn.Close()
|
|
|
|
|
|
Date Added:
02/09/2007 13:04:00
|
|
|
|
|
|
|
Your Details: Not Logged In
Join Date: N/A
Last Logon: N/A
Code Snippets: N/A
Code Comments:
Forum Posts: N/A
Forum Subjects: N/A
Site Wide
Code Snippets: 32
Code Comments:
Forum Posts: 52
Forum Subjects: 24
|
|
|
|
|
|
|
|
|
|
|