|
-
Mar 24th, 2004, 07:06 AM
#1
Thread Starter
Lively Member
SQLConnection Problem
Hello
I have written following code for getting connectivity with SQL Server. DB server is on separate pc. I am giving its IP address in connection string.
Dim myConnectionString As String = "Provider=SQLOLEDB; Data Source=IP Addr of db server; Initial Catalog=DB Name; User Id=UserName; Password=Password;"
Dim myConnection As New SqlConnection(myConnectionString)
myConnection.Open()
Dim myReadQuery As String = "select * from dbAkitaAdmin"
Dim myCommand As New SqlCommand(myReadQuery)
Dim adapter As New SqlDataAdapter()
Dim myDataSet as New DataSet()
adapter.SelectCommand = myCommand
adapter.Fill(myDataSet)
But it is giving me error as follows
Compiler Error Message: BC30002: Type 'SqlConnection' is not defined.
Pls suggest the way for this connectivity.
Also pls kindly expln about usage of SqlCommand, SqlDataAdapter and SqlDataReader classes.
Thanks
Mahesh
Everybody is always learning something new ! 
-
Mar 24th, 2004, 10:46 PM
#2
I wonder how many charact
I'm a little surprised that iSystem.Data isn't referenced and imported by default in your project properties, but anyway:
Use:
VB Code:
Dim myConnection As New System.Data.SqlClient.SqlConnection
-
Mar 25th, 2004, 05:39 AM
#3
Thread Starter
Lively Member
Hello
You are right, Imports statement must be there. I have added it as follows
Imports System.Data
Imports System.Data.SqlClient
Sub Page_Load(sender As Object, e As EventArgs)
Dim myConnectionString As String = "Server=IP Addr of DB Server;Database=DB Name;User ID=uname;Password=pwd;Integrated Security=SSPI"
Dim myConnection As New SqlConnection(myConnectionString)
myConnection.Open()
Dim myReadQuery As String = "select * from dbAkitaAdmin"
Dim myCommand As New SqlCommand(myReadQuery)
Dim adapter As New SqlDataAdapter()
Dim myDataSet as New DataSet()
adapter.SelectCommand = myCommand
adapter.Fill(myDataSet)
gridTest.DataSource = dataset
gridTest.DataBind
rdrTest.Close
cmdTest.Dispose
conTest.Close
End Sub
But now it is giving me new error :
Compiler Error Message: BC30465: 'Imports' statements must precede any declarations.
Source Error:
Line 2: <script runat="server">
Line 3:
Line 4: Imports System.Data
Line 5: Imports System.Data.SqlClient
Line 6:
Then I have added Option Strict On, before Imports Statement. But still error is displayed.
Compiler Error Message: BC30627: 'Option' statements must precede any declarations or 'Imports' statements.
Source Error:
Line 2: <script runat="server">
Line 3:
Line 4: Option Strict On
Line 5:
Line 6: Imports System.Data
Please kindly suggest some solution.
Thanks
Mahesh
Everybody is always learning something new ! 
-
Mar 25th, 2004, 05:02 PM
#4
I wonder how many charact
Option strict On must be the first line in your code.
Imports must follow that and BEFORE any other code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|