Click here to Skip to main content
15,892,797 members

Connecting Sql Server 2005 to ASP.net

drkterror1 asked:

Open original thread
Hello guys, first of all I would like to say my thanks to all for your help. Now I am facing another problem. My Instructor wanted me to use Microsoft SQL Server 2005. The problem is I don't know how to use it please help me.
Here is my trial code:
XML
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Web.UI" %>

<script language="VB" runat="server">

    Sub btnLogin_OnClick(Src As Object, E As EventArgs)
        Dim strSQL As String
        Dim myCommand As OleDbCommand
        Dim strUserURL As String
        Using connection As New OleDbConnection("datasource1")
            strSQL = "SELECT * FROM [Admin] " _
            & "WHERE LogName='" & Replace(txtUsername.Text, "'", "''") & "' " _
            & "AND LogPass='" & Replace(txtPassword.Text, "'", "''") & "'"
            myCommand = New OleDbCommand(strSQL, connection)
            connection.Open()
            strUserURL = myCommand.ExecuteScalar()
            connection.Close()

            If strUserURL <> "" Then
                lblInvalid.Text = ""
                FormsAuthentication.SetAuthCookie(txtUsername.Text, True)
                Response.Redirect("bob.aspx")
            Else
                lblInvalid.Text = "Sorry... try again..."
            End If

        End Using
    End Sub


</script>

<html>
<head>
<title>ASP.NET Login</title>
</head>
<body>

<h2>Please Login:</h2>

<p>
<asp:Label id="lblInvalid" runat="server" />
</p>

<form runat="server">

    Username: <asp:TextBox id="txtUsername" runat="server" /><br />
    Password: <asp:TextBox id="txtPassword" TextMode="password" runat="server" Width="155px" /><br />
    <br />
    position: &nbsp;&nbsp;
    <asp:TextBox id="items" runat="server" /><br />
    <br />
    <br />
    <asp:Button id="btnLogin" runat="server"
        text="Login" OnClick="btnLogin_OnClick" Width="221px"
    />&nbsp;
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestSQLConnectionString %>"
        SelectCommand="SELECT * FROM [Admin]" OnSelecting="SqlDataSource1_Selecting"></asp:SqlDataSource>
</form>

</body>
</html>


Here is the web.config:
XML
<?xml version="1.0" encoding="utf-8" ?>
<configuration>

    <!-- enable forms authentication -->
    <system.web>
        <authentication mode="Forms">
            <forms name="ASP101SampleAuth" loginUrl="login_db_nav.aspx" />
        </authentication>
    </system.web>

    <!-- set secure page to reject anonymous users -->
    <location path="bob.aspx">
        <system.web>
            <authorization>
                <allow users="*" />
                <deny users="none" />
            </authorization>
        </system.web>
    </location>


</configuration>


Now here is the error I'm trying to debug:
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30456: 'SqlDataSource1_Selecting' is not a member of 'ASP.login_db_nav_aspx'.

Source Error:



Line 57:        text="Login" OnClick="btnLogin_OnClick" Width="221px"
Line 58:    />&nbsp;
Line 59:     <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestSQLConnectionString %>"
Line 60:         SelectCommand="SELECT * FROM [Admin]" OnSelecting="SqlDataSource1_Selecting"></asp:SqlDataSource>
Line 61: </form>


Source File: C:\Documents and Settings\oca14625\Desktop\login_db_nav.aspx    Line: 59



Please help me.. I don't know where I got it wrong..
Tags: Visual Basic, ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900