Solved

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

Posted on 2004-09-29
5
197 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

749 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