Hi, everyone. I am beginning to learn how to create Business Objects (in the form of
VB.NET Dlls) and I am having a terrible time trying to debug this one. Everything looks correct, but when I run the ASP.NET page to use the DLL, it always returns Nothing.
Can someone look at my code and give me some guidance? I would really appreciate it. Thanks
Logan Scott
--------------------------------------------
Here is the
VB.NET code portion:
Imports System
Imports System.Data
Imports System.Data.SqlClient
Namespace SQLDb
Public Class Database
Public objCS As String
public objConn As SqlConnection
Public objCmd As SqlCommand
Public Function SelectSQL(ByVal strSQL As String) As SqlDataReader
Try
objConn = New SqlConnection(objCS)
objCmd = New SqlCommand(strSQL, objConn)
objCmd.Connection.Open()
Return objCmd.ExecuteReader
objCmd.Connection.Close()
Catch ex As Exception
Return Nothing
End Try
End Function
End Class
End Namespace
----------------------------------------------
You can compile the
VB.NET code with this:
vbc /t:library /out..\bin\SQLDb.dll /r:System.dll /r:System.Data.dll Database.
vb
----------------------------------------------
Here is the ASP.NET code:
<%@ Page Language="
VB" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SQLClient" %>
<%@ import Namespace="SQLDb" %>
<script runat="server">
' Insert page code here
'
Sub btnSQL_Click(sender As Object, e As EventArgs)
Dim objDatabase as new SQLDb.Database
Dim objCmd As New SqlCommand(strSQL, objConn)
Dim objReader as SQLDataReader = objCmd.ExecuteReader
objDatabase.SQLConnString = "Data Source=(LOGANLAPTOP);" & _
"Initial Catalog=Northwind;" & _
"Integrated Security=SSPI"
objReader = objDatabase.SelectSQL("SELECT * FROM Employees")
If Not objReader Is Nothing Then
dgSQLData.DataSource = objReader
dgSQLData.DataBind
objReader.Close
Else
txtMessage.Text = "objReader = Nothing" & vbcrlf
txtMessage.Text = txtMessage.Text & "objDataBase.SQLConnString = " & _
objDatabase.SQLConnString
End if
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
</p>
<p>
<asp:TextBox id="txtMessage" runat="server" Width="561px" Height="134px" TextMode="MultiLine"></asp:TextBox>
</p>
<p>
<asp:Button id="btnSQL" onclick="btnSQL_Click" runat="server" Width="84px" Text="Test SQL"></asp:Button>
</p>
<p>
<asp:DataGrid id="dgSqlData" runat="server" Width="100%" BorderColor="Black" CellPadding="4" Font-Names="Arial" Font-Size="8pt">
<AlternatingItemStyle backcolor="#CCCCCC"></AlternatingItemStyle>
<ItemStyle backcolor="White"></ItemStyle>
<HeaderStyle backcolor="#CCCC99"></HeaderStyle>
</asp:DataGrid>
</p>
</form>
</body>
</html>