Chris Millard
asked on
SQL queries using VB 2010
Although OK with VB, I have never coded anything to connect to SQL and run queries.
I have my connection already as "conn"
What I want to do is run a query and store the result in a variable.
My query is:-
How do I do this in VB 2010?
Thanks
I have my connection already as "conn"
What I want to do is run a query and store the result in a variable.
My query is:-
SELECT SUM(timetaken) FROM dbo.ACTIONS where who='roybridge' and Whe_ >= '03/01/2011'
How do I do this in VB 2010?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This is the full code:-
Dim conn As New SqlConnection()
conn.ConnectionString = "Data Source=RCSRV01;Initial Catalog=NetHDRedcatSQL;Persist Security Info=True;User ID=sa;Password=letmein"
Dim cmd As New SqlCommand
cmd.Connection = conn
cmd.CommandType = CommandType.Text
cmd.CommandText = ""
Dim strOutput As String
conn.Open()
strOutput = cmd.ExecuteScalar
conn.Close()
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
D'oh! Stupidly I didn't see that!!!
ASKER
strOutput = cmd.ExecuteScalar
I get an error "ExecuteScalar: CommandText property has not been initialized"