Solved

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

Posted on 2004-09-29
5
198 Views
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
        oSQLConn.Open()

But I get the error like this:

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

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"

Thanks
vm
0
Comment
Question by:vmandem
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 96

Expert Comment

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

Bob
0
 

Author Comment

by:vmandem
ID: 12183088
TheLearnedOne

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.
vm
0
 
LVL 8

Accepted Solution

by:
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.
0
 
LVL 96

Expert Comment

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


Dim connectionSQL As SqlConnection = New SqlConnection(connectionString)

conn.Open()

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

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

Bob
0
 
LVL 96

Expert Comment

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

Bob
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

728 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