Команды SQL. Установка SQL сервера и написание запросов к SQL серевру. Листинги программ на Visual Basic с SQL-запросами. Команды SQL
Команды SQL server
Примеры работы с SQL из Visual Basic

Примеры работы с SQL из Visual Basic


    Продолжение
    
    примеры SQL запросов
    
    "Select * From Title Where [Year Published] < 1889"
    "Delete From Titles Where [Year Published] < #1/1/1889#"
    "Select Name, Picture From Authors Where Date_of_Birth = #2/1/1947#"
    "Select * From Employees"
    "Select [First Name], [Last Name] From Employees"
    "Select Employees, Department, SupvName From Supervisors, _
     Employees Where Employees.Department = Supervisorts.Department"
    "Select Distinct [Last Name] From Employees"
    "Select [Last Name], Salary From Employees Where Salary > 2100"
    "Select * From Orders Where [Shipped Date] = #5/12/93#"
    "Select [Product Name], Sum ([Units in Stock]) From Products _
     Group By [Product Name]"
    "Select * From Employees Order By [Last Name], Asc"
    "Select [Last Name], [First Name] From Employees Order by 2 Asc"
    

    Подключение Visual Basic 2008 к sql server 2008
    
    Результаты записываются в sqldatareader
    
    Imports System.Data.SqlClient
     Public Class Form1
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     Dim connectionString As String
     Dim sqlCnn As SqlConnection
     Dim sqlCmd As SqlCommand
     Dim sql As String
    
     connectionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
     sql = "Your SQL Statement Here , like Select * from product"
    
     sqlCnn = New SqlConnection(connectionString)
     Try
     sqlCnn.Open()
     sqlCmd = New SqlCommand(sql, sqlCnn)
     Dim sqlReader As SqlDataReader = sqlCmd.ExecuteReader()
     While sqlReader.Read()
     MsgBox(sqlReader.Item(0) & " - " & sqlReader.Item(1) & " - " & sqlReader.Item(2))
     End While
     sqlReader.Close()
     sqlCmd.Dispose()
     sqlCnn.Close()
     Catch ex As Exception
     MsgBox("Can not open connection ! ")
     End Try
     End Sub
     End Class
    
    
Скачать бесплатно
    

    Сколько таблиц в базе данных (VB.NET)
    
    Запрос типа Select DISTINCT(name) FROM sys.Tables
    
    Imports System.Data
    Imports System.Data.SqlClient
    Public Class Form1
    
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     Dim connetionString As String
     Dim connection As SqlConnection
     Dim command As SqlCommand
     Dim adapter As New SqlDataAdapter
     Dim ds As New DataSet
     Dim tables As DataTable
     Dim i As Integer
     Dim sql As String
    
     connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password"
     sql = "Select DISTINCT(name) FROM sys.Tables"
     connection = New SqlConnection(connetionString)
    
     Try
     connection.Open()
     command = New SqlCommand(sql, connection)
     adapter.SelectCommand = command
     adapter.Fill(ds)
     adapter.Dispose()
     command.Dispose()
     connection.Close()
    
     For i = 0 To ds.Tables(0).Rows.Count - 1
     MsgBox(ds.Tables(0).Rows(i).Item(0))
     Next
    
     Catch ex As Exception
     MsgBox("Can not open connection ! ")
     End Try
     End Sub
    End Class
    
    
Читаем далее >>
    
    Английский язык
    



    


    Добавить комментарий
    
    Tags:
, , , , , ,
    
    
Генератор бэк линков - скачать бесплатно в ZIP ( http://popochte.narod.ru/ )
    
    

Команды SQL. Установка SQL сервера и написание запросов к SQL серевру. Листинги программ на Visual Basic с SQL-запросами. ZIP Visual Basic SQL