?
Solved

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

Posted on 2004-09-29
5
Medium Priority
?
199 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 120 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

770 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