Type SqlConnection is not defined????
Question
Tuesday, March 25, 2008 11:30 AM
Hello All!
I Wrote this code to connect to a mssql server 2005 express db in visual basic 2008 express edition.
Public Function SelectRows(ByVal dataSet As DataSet, ByVal connectionString As String, ByVal queryString As String) As DataSet
Using connection As New SqlConnection(connectionString)
Dim adapter As New SqlDataAdapter()
adapter.SelectCommand = New SqlCommand(queryString, connection)
adapter.Fill(dataSet)
Return dataSet
End Using
End Function
Problem is that i allways get the Error msg Type SqlConnection is not defined.
Im totally new to VS Programming. Anyone can help me out?
Thanks alot.
All replies (3)
Tuesday, March 25, 2008 1:40 PM âś…Answered
At the very top of the page assure that you have imported in the sqlclient namespace. You would otherwise have to create the connection, and other data objects calling the full namespace System.Data.SqlClient.SqlConnection. Let me know if this works.
Code Snippet
Imports System.Data.SqlClient
Public Class Form1
Public Function SelectRows(ByVal dataSet As DataSet, ByVal connectionString As String, ByVal queryString As String) As DataSet
Using connection As New SqlConnection(connectionString)
Dim adapter As New SqlDataAdapter()
adapter.SelectCommand = New SqlCommand(queryString, connection)
adapter.Fill(dataSet)
Return dataSet
End Using
End Function
End Class
Tuesday, March 25, 2008 2:39 PM
Thanks Alot!!! Love you!, it works!
Tuesday, March 25, 2008 2:42 PM
You can download 101 VB/C# .NET examples from the below links. These download provide a great reference.
vs 2005
http://msdn2.microsoft.com/en-us/vbasic/ms789075.aspx
vs 2003
Best of Luck!!