
February 19th, 2013, 03:01 PM
|
|
Registered User
|
|
Join Date: Feb 2013
Posts: 2
Time spent in forums: 1 h 1 m 34 sec
Reputation Power: 0
|
|
Hello,
in VB.NET:
Code:
Dim connectionString As String
Dim sql As String
Dim pwd As String
Dim user As String
Dim sqlserv As String
Dim sqldb As String
sqlserv = localhost\sqlexpress 'your server
sqldb = mydbs 'the database
user = sa 'user who has access to the db
pwd = admin 'user's password
'The connection string below
connectionString = "Data Source=" & sqlserv & ";Initial Catalog=" & sqldb & ";User ID=" & user & ";Password=" & pwd
Dim sqlSelect As String
'SQL select below dbo.Table is your table which contains the information, also you can order if you want
sqlSelect = "SELECT Id, Start, End, Distance FROM dbo.Table WHERE (Start = '" & TextBox1.Text & "') AND (End = '" & TextBox2.Text & "' ORDER BY Distance "
Dim sqlCnn As SqlConnection
Dim sqlCmd As SqlCommand
sqlCnn = New SqlConnection(connectionString)
Dim dataadapter As New SqlDataAdapter(sqlSelect, connectionString)
Dim distance As string
Try
sqlCnn.Open()
sqlCmd = New SqlCommand(sql, sqlCnn)
Dim sqlReader As SqlDataReader = sqlCmd.ExecuteReader() While sqlReader.Read()
distance = sqlReader.Item("distance")
End While sqlReader.Close()
sqlCmd.Dispose()
sqlCnn.Close()
MessageBox.Show(distance, "Result")
Catch ex As Exception
MessageBox.Show("Houston we have a problem...", "Error")
End Try
|