C#与Asp.net与OBDC的MySQL使登录和注册不起作用 [英] C# With Asp.net MySQL with OBDC Making Login and Registration Not Working Problems

查看:97
本文介绍了C#与Asp.net与OBDC的MySQL使登录和注册不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果有人可以帮助我解决问题,我将不胜感激:使用OBDC在MySql中使用C#注册页面

I would be very grateful if someone could help me with a problem: registration page in C# for MySql using OBDC

我不能使用任何内置的asp.net功能.

I can't use any of the built in asp.net features.

我正在上课.虽然我知道还有其他可能更好的方法来制作连接字符串,但这是教师的方法. 我创建了一个名为User的类,并且正在尝试制作注册页面.尚未在登录页面上启动,但是需要使用会话ID进行登录,并且在登录和注册页面上都需要有一个条目,无论用户是否登录,该条目都可以显示.

I'm doing it for a class. And while I know there are other possibly better ways to make the connection string, this is how the instructor does it. I have a class called User created, and am trying to make the registration page. Haven't started on the login page but need to do a login with session id and an entry on both login and registration pages that shoes if user is logged in or not.

因此对于初学者来说,我的注册页面在"NewRegis.create()" line 23.

So for starters, my registration page keeps getting an error on the "NewRegis.create()" line 23.

它也说:

c:\Users\Lau\Documents\SQL Class\Project_homework3\App_Code\User.cs(23,34): error CS1002: ; expected
        Line 21:                 NewRegis.email = email.Text;
        Line 22:                 NewRegis.password = password.Text;
        Line 23:                 NewRegis.create()
        Line 24:             }
        Line 25: 

这是注册aspx文件和文件后面代码的代码.....

So here is the code for the registration aspx file and for the code behind file.....

这是registration.aspx文件的代码:

Here is the code for the registration.aspx file:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="registration.aspx.cs" Inherits="registration.NewRegis" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
   <head runat="server">
   <title></title>
   </head>
        <body>
            <div>
            <div>
            <h1>Registration Page</h1> 
            <p>To register, please enter the following information and then submit.</p>
            </div>
            <br />
            <br />
            <br />
            <div>
            <form id="form1" runat="server">
            <asp:Label ID="EmailLab" runat="server" Text="Email Address (will be login)" 
                Value=""></asp:Label>
            <br />
            <asp:TextBox ID="email" runat="server" Width="205px"></asp:TextBox>
            <br />
            <br />
            <asp:Label ID="FirstName" runat="server" Text="First Name"></asp:Label>
            <br />
            <asp:TextBox ID="first_name" runat="server" Width="205px"></asp:TextBox>
            <br />
            <br />
            <asp:Label ID="LastNameLab" runat="server" Text="Last Name"></asp:Label>
            <br />
            <asp:TextBox ID="last_name" runat="server" Width="205px"></asp:TextBox>
            <br />
            <br />
            <asp:Label ID="passLab" runat="server" 
                Text="Password (Six Characters.)"></asp:Label>
            <br />
            <asp:TextBox ID="password" runat="server" Width="205px"></asp:TextBox>
            <br />
            <br />
            <br />


<asp:Button ID="ButtonSubmit" OnClick="submit" PostBackUrl="~/registration.aspx" Text="Submit" runat="server" />

<asp:RequiredFieldValidator ID="ReqFieldValFirst" ControlToValidate="first_name" Text="First name is required!" runat="server" />  

<asp:RequiredFieldValidator ID="ReqFieldValLast" ControlToValidate="last_name" Text="Last name is required!" runat="server" /> 

<asp:RequiredFieldValidator ID="ReqFieldValEmail" ControlToValidate="email" Text="Email is required!" runat="server" /> 

<asp:RequiredFieldValidator ID="ReqFieldValPass" ControlToValidate="password" Text="Password is required!" runat="server" /> 

<br />
<br />
<br />

        </form>
     </div>
   </div>
 </body>
</html>


这是NewRegis.create出现错误的代码隐藏文件的代码:


Here is the code for the codebehind file where the NewRegis.create is getting an error:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace registration
{
    public partial class NewRegis : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (IsPostBack)
            {

                User NewRegis = new User()
                NewRegis.first_name = first_name.Text;
                NewRegis.last_name = last_name.Text;
                NewRegis.email = email.Text;
                NewRegis.password = password.Text;

                NewRegis.create();

            }
        }
    }
}


我没有包含用户类文件,但是如果有帮助,我可以重新加载它.我应以下要求将此信息最小化.

对于我所获得的任何帮助,我将不胜感激.我不知道为什么我不断在NewRegis.create()上收到错误消息; 但是当我将鼠标悬停在用户NewRegis = new User()中的用户中的用户"上时,提示告诉我'System.Web.UI.Page.User' is a 'property' but is used like a 'type'


I didn't include the user class file but if that would help, I can reload it. I minimized this post at the request below.

I'd be grateful for any help on what I've got. I have no idea why I keep getting the error on the NewRegis.create(); but when I hover over the "User" in User in User NewRegis = new User() the tip tells me 'System.Web.UI.Page.User' is a 'property' but is used like a 'type'

推荐答案

花一些时间遍历所有内容;-)

Took some time to wade through all of it ;-)

error CS1002: ; expected

表示您忘记了行尾的终止分号.解决这个问题对您来说是微不足道的,对吧?

means as it says that you forgot a terminating semicolon at the end of a line. Solving that should be trivial to you, right?

System.Web.UI.Page.User is a 'property' but is used like a 'type

编译器将您的用户类解释为与System.Web.UI.Page.User属性相同.名称冲突.

The compiler interprets your user class the same as System.Web.UI.Page.User property. A name conflict.

您可以通过将用户类重命名为MyUser之类的方法来解决此问题,而不仅仅是更改命名空间(!)

You can solve it by renaming your User-class to something else like MyUser, not just alter the namespace(!)

或根据您的情况指定类的全限定名

Or specify the full qualified name of the class, in your case

PET.User NewRegis = new PET.User();

这篇关于C#与Asp.net与OBDC的MySQL使登录和注册不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆