I am really new at using SQL Server with an ASP.Net page. I am confused. I think I understand Michael's code better. But I still cannot get it to work. I am getting the following error now:
Compiler Error Message: BC30289: Statement cannot appear within a method body. End of method assumed.
Source Error:
|
Line 4:
Line 5: <%
Line 6: Function SQLConnection(servername,username,password,database) as SQLConnection
|
I don't understand about SQLCommand because I noticed that it was not defined in Michael's code.
Here's my code now:
<%
Function SQLConnection(servername,username,password,database) as SQLConnection
servername = "myservername"
username = "username"
password = "password"
databasename = "dbname"
Dim conString As String
conString = conString.Format("server={0};User ID={1};Password={2};Database={3};", servername, username, password, databasename)
Dim objSQLCon As New System.Data.SQLClient.SqlConnection(conString)
Return objSQLCon
Dim dtaMusic As New OleDbDataAdapter()
Dim dtsMusic As New DataSet()
Dim StrSQL As String
SQLConnection.ConnectionString = conString
SQLConnection.Open()
'Start SQL statement
strSQL = "Select * From Spa2"
'Add Order By
strSQL = strSQL & " Order By SpaStoreName"
Trace.Warn ("strSQL = " & strSQL)
'Set the Command Object properties
SQLCommand.Connection = SQLConnect
SQLCommand.CommandType = CommandType.Text
SQLCommand.CommandText = strSQL
'Point the DataAdapter object at a Command object to work with
dtaMusic.SelectCommand = SQLCommand
'Get the data from the database and
'put it into a DataTable object named dttMusic in the DataSet object
dtaMusic.Fill(dtsMusic, "dttMusic")
'Bind the DataGrid
dtgMusic.DataSource = dtsMusic
dtgMusic.DataBind()
End Function