应输入 class、delegate、enum、interface 或 struct
我在编译连接数据库登入功能的时候 取消按钮的指令 private void btnCancel_Click(object sender, EventArgs e)
{
txtName.Text = "";
txtPwd.Text = "";
txtName.Focus();
}
提示错误 说" 应输入 class、delegate、enum、interface 或 struct"
完整指令:
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace MySchool
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
private void Login_Load(object sender, EventArgs e)
{
}
private void btnYes_Click(object sender, EventArgs e)
{
string userName = txtName.Text;
string password = txtPwd.Text;
string connString=@"Data Source=f-pc;Initial Catalog=MySchool;Integrated Security=True";
SqlConnection connection=new SqlConnection (connString);
string sql=String.Format("select count(*) from [User] where userName='{0}' and password='{1}'",userName,password );
try
{
connection.Open ();
SqlCommand command=new SqlCommand(sql,connection );
int num=(int)command.ExecuteScalar();
if(num> 0 )
{
MessageBox.Show("欢迎进入成绩管理系统!","登入成功", MessageBoxButtons.OK,MessageBoxIcon.Information);
MainFrm mainForm=new MainFrm();
mainForm.Show();
this.Visible=false;
}
else
{
MessageBox.Show ("您输入的用户名或密码错误!","登入失败",MessageBoxButtons.OK,MessageBoxIcon.Exclamation );
}
}
catch (Exception ex)
{
MessageBox.Show (ex.Message,"操作数据库出错!",MessageBoxButtons.OK ,MessageBoxIcon.Exclamation );
}
finally
{
connection.Close();
}
}}
private void btnCancel_Click(object sender, EventArgs e)
{
txtName.Text = "";
txtPwd.Text = "";
txtName.Focus();
}
}
(跟着书一步一步做的)
希望达人帮我解答一下