Reputation: 47
I am learning how to write code in asp.net and this is my first crack at it. I am not sure what I'm doing wrong.
These are the errors I keep getting when I run this code.
(16:9) The type or namespace name 'DataSet' could not be found (are you missing a using directive or an assembly reference?)
(16:27) The type or namespace name 'DataSet' could not be found (are you missing a using directive or an assembly reference?)
(17:9) The type or namespace name 'DataSetTableAdapters' could not be found (are you missing a using directive or an assembly reference?)
(17:62) The type or namespace name 'DataSetTableAdapters' could not be found (are you missing a using directive or an assembly reference?)
(19:27) The name 'Login1' does not exist in the current context
(20:27) The name 'Login1' does not exist in the current context
login.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body background="images\reading.jpg">
<form id="form1" runat="server">
<div><font size="6" color="white"><center>
<asp:Login ID="Login1" runat="server" OnAuthenticate="Login1_Authenticate">
</asp:Login>
</font></center></div>
<div><p><font size="6" color="white"><center>Are you a new user? Please<center></font></p></div>
<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click"><font size="6" color="red"><center>Sign Up</center></font></asp:LinkButton>
</form>
</body>
</html>
login.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
DataSet lds = new DataSet();
DataSetTableAdapters.LoginTableAdapter loginTA = new DataSetTableAdapters.LoginTableAdapter();
loginTA.Fill(lds.Login);
string userName = Login1.UserName;
string password = Login1.Password;
if (userName != null)
{
var pwd = from login in lds.Login
where userName.Contains(login.user_name)
select login.pwd;
foreach (var item in pwd)
{
if (item == password)
{
Response.Redirect("files.aspx");
}
}
}
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("signup.aspx");
}
}
Upvotes: 1
Views: 7442
Reputation: 12581
You need to add the line using System.Data;
near the other using
statements. This will allow your class to access the DataSet class without fully qualifying the class name.
Each time you see the error
The type or namespace name ... could not be found
You need to identify the namespace where the class is defined and add a using statement for said namespace. Another option is to include the namespace when using the class but that wouldn't work for extension methods.
A good Visual Studio tip is to right click on the class names that are giving you these errors, you should see Quick Fix option to automatically add the required using
statement.
Upvotes: 1
Reputation: 106
You need to include the System.Data
reference up top with using System.Data;
Upvotes: 0