我的页面没有重定向到我指定的页面。虽然我这样做,却说The name "Response" does not exist in the current context
还请帮我在注册时获取数据库中的寄存器值。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace LoginSystem123
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private void buttonLogin_Click(object sender, EventArgs e)
{
var myConnection = new SqlConnection();
myConnection.ConnectionString = @"Data Source=mukesh-PC\SQLEXPRESS;Initial Catalog=testDb;Integrated Security=True;Pooling=False";
var myCommand = new SqlCommand();
var cmd = "SELECT * FROM [User] Where [User].Email =" + "'" + textBoxEmail.Text + "'";
myCommand.CommandText = cmd;
myCommand.CommandType = CommandType.Text;
myCommand.Connection = myConnection;
myConnection.Open();
var myReader = myCommand.ExecuteReader();
bool isRegisteredUser = myReader.Read();
if (isRegisteredUser)
{
var PasswordFromDatabase = myReader.GetString(5);
if (textBoxPassword.Text == PasswordFromDatabase.TrimEnd())
{
MessageBox.Show("Successfully Logged on !");
}
else
{
MessageBox.Show("Invalid password. Try again");
}
}
else
{
MessageBox.Show("Invalid user");
}
}
/* private void buttonSignUp_Click(object sender, EventArgs e)
{
Response.Redirect("SignUp.cs");
}
*/
private void buttonSignUp_Click_1(object sender, EventArgs e)
{
Response.Redirect("SignUp.cs");
}
}
}
答案 0 :(得分:3)
Response.Redirect
用于重定向到ASP网站中的另一个页面 - 在Windows窗体中不能像这样工作。
如果SignUp.cs
定义了Form
,您可以执行以下操作来显示它:
var signup = new SignUp();
signup.ShowDialog();
如果您让我们更多地了解您要做的事情,我们可能会更有帮助。
答案 1 :(得分:1)
Response.Redirect仅适用于Web应用程序,看起来您正在编写Windows应用程序。
你应该这样做:
SignUp su = new SignUp();
su.Show();
this.Hide();