Hi how do I connect to my sqlserver database from VB.NET

Posted on 2004-09-29
Last Modified: 2010-07-27
I'm using the connection string like this:

Dim strconnection = "Server=local;Database=VM;User ID=sa;Password=hello;Trusted_Connection=False"

and this is the code I'm using to open the connection

   Dim oSQLConn As SqlConnection = New SqlConnection
        oSQLConn.ConnectionString = strconnection

But I get the error like this:

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in

Additional information: System error.

What could be the problem. I checked the sqlserver and I set the username and password for the VM database as
"sa" and "hello"

Question by:vmandem
  • 3
LVL 96

Expert Comment

by:Bob Learned
ID: 12183060
Can connect to SQL Server with Windows Authentication?


Author Comment

ID: 12183088

I got connected to the sqlserver and I changed the server name and it worked. Can you please tell me how to retreive data from the sql query to a recordset and I want to pass the recordset value to a textbox.

Thanks and appreciate your help.

Accepted Solution

wguerram earned 30 total points
ID: 12183223

dim cmd as New sqlCommand("SELECT * FROM YourTable", oSQLConn)
dim dr as sqlDataReader = sqlCommand.ExecuteReader()

if dr.Read then
     me.TextBox1.Text = dr("ColumnName").ToString
end if

subsequent calls to dr.Reade will bring you the next row.
LVL 96

Expert Comment

by:Bob Learned
ID: 12183236
You need to fill in the holes:

Dim connectionSQL As SqlConnection = New SqlConnection(connectionString)


Dim commandGetData As SqlCommand = New SqlCommand(queryString, connectionSQL)

Me.TextBox1.DataBindings.Add(New Binding("Text", DataSet1, "Table.Field"))

LVL 96

Expert Comment

by:Bob Learned
ID: 12183243
Right at the same time!!!


Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net - CSV to Oracle table 4 52
Get Count in a variable with 5 digits always 1 27
LINQ - C# to VB convertion 12 46
SQL syntax in 5 28
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now