How do I connect to SQL

In VB6 I use to use a module modDataAccess to set a ConnectionString
Public Const sDataConn = "Provider=MSDASQL;Persist Security Info=False;uid=sa;pwd=;Initial;Catalog=falDB;Data Source=falDB;Connect Timeout=600"
Public Conn As ADODB.Connection
Public RS As ADODB.Recordset

And used it in:              
Dim Conn As New ADODB.Connection
Conn.Open sDataConn
Conn.Execute "UPDATE tblAnalysis SET dtmBeginDate = ('" & FixDate(DTPickerBeginDate.Value) & "')"
Conn.Execute "DELETE FROM rptAgeAnalysis"
Conn.Execute "INSERT INTO aTable (intTemp, nvcTemp) VALUES (1,1)"

And when I want a value for a variable:
                Dim SystemDate as Date
                Set RS = New ADODB.Recordset
                RS.Open "Select dtmSystemDate FROM tblSystemDate WHERE   ……", sDataConn
                If Not RS.EOF Then SystemDate = RS("dtmSystemDate")
                Set RS = Nothing

what can I use in that are simular to above ?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dirk HaestProject managerCommented:
An example can be found here:
Dirk HaestProject managerCommented:
To retrive just one value from the database, use the executescalar-function
Om PrakashCommented:
Please check the example
Imports System.Data.SqlClient

Dim sConnection As String = "-- connection string -- "

Dim objCommand As New SqlCommand
objCommand.CommandText = "Select dtmSystemDate FROM tblSystemDate WHERE . . . . "
objCommand.Connection = New SqlConnection(sConnection)

Dim objDataReader As SqlDataReader = objCommand.ExecuteReader()

If objDataReader.HasRows Then
	Do While objDataReader.Read()
		MessageBox.Show("Field: " & Convert.ToString(objDataReader(0)))
Console.WriteLine("No data found")
End If

Open in new window

mariostruwigAuthor Commented:
how do I get the value of "dtmSystemDate" into the variable say "SystemDate"
Dirk HaestProject managerCommented:
What datatype is dtmSystemDate  ?
In example below, I assume it's a string
Dim SystemDate As String
Dim sql As String = _
     "Select dtmSystemDate FROM tblSystemDate WHERE   ……"

    Using conn As New SqlConnection(connString)
        Dim cmd As New SqlCommand(sql, conn)
            SystemDate = cmd.ExecuteScalar().ToString()
        Catch ex As Exception
        End Try
    End Using

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.