Solved

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

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

10 Experts available now in Live!

Get 1:1 Help Now