Модератор: Ramzes
Private Connection As SqlConnection
Public Sub Connect()
Dim ConnString As New SqlConnectionStringBuilder
ConnString.DataSource = ConnectOptions.Host & "," & ConnectOptions.Port
ConnString.InitialCatalog = "database"
ConnString.UserID = "login"
ConnString.Password = "pass"
ConnString.MultipleActiveResultSets = True
Connection = New SqlConnection(ConnString.ConnectionString)
Try
Connection.Open()
Catch ex As Exception
Throw New Exception("Ошибка подключения к БД (" & ConnString.ConnectionString & "): " & ex.ToString)
End Try
End Sub
Dim Name as String = Nothing 'Наша переменная
Dim Command As New SqlCommand("", Connection)
'...
Command.CommandText = "SELECT * FROM table WHERE id=1;"
'...
Try
Using Query As SqlDataReader = Command.ExecuteReader()
Query.Read()
If Not Query.IsDBNull(1) Then
Name = Query.GetString(1) 'Query.GetString(номер_столбца)
End If
End Using
Catch ex As Exception
#If DEBUG Then
MsgBox(ex.ToString)
#End If
End Try
MsgBox Name
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 35