首页上一页 1 下一页尾页 1 条记录 1/1页
c# 登陆窗体,连接数据库德时候 这些错误
发表在C#图书答疑
2010-07-07
是否精华
是
否
版块置顶:
是
否
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection();
con.ConnectionString = MySqlConnection;
con.Open(); //连接数据库
SqlCommand cmd;
cmdString = "select * from 用户名 where 用户名=" + this.user_TB.Text.Trim();
cmd = new SqlCommand(cmdString, con);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
if (this.password_TB.Text.Trim() == reader["密码"].ToString().Trim())
{
MessageBox.Show("登录成功!");
}
else
{
MessageBox.Show("密码错误!");
}
}
else
{
MessageBox.Show("用户名不存在!");
}
reader.Close();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("登录失败:" + ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("取消登陆");// textBox1.Text = textBox2.Text = "";
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.CheckState == CheckState.Checked)
{
MessageBox.Show("记住密码");
}
else
{
MessageBox.Show("取消");
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
}
}
错误列表
错误 1 当前上下文中不存在名称“MySqlConnection”
错误 2 当前上下文中不存在名称“cmdString”
错误 3 “WindowsApplication12.Form1”并不包含“user_TB”的定义
错误 4 当前上下文中不存在名称“cmdString”
错误 5 “WindowsApplication12.Form1”并不包含“password_TB”的定义
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new SqlConnection();
con.ConnectionString = MySqlConnection;
con.Open(); //连接数据库
SqlCommand cmd;
cmdString = "select * from 用户名 where 用户名=" + this.user_TB.Text.Trim();
cmd = new SqlCommand(cmdString, con);
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
if (this.password_TB.Text.Trim() == reader["密码"].ToString().Trim())
{
MessageBox.Show("登录成功!");
}
else
{
MessageBox.Show("密码错误!");
}
}
else
{
MessageBox.Show("用户名不存在!");
}
reader.Close();
con.Close();
}
catch (Exception ex)
{
MessageBox.Show("登录失败:" + ex.Message);
}
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("取消登陆");// textBox1.Text = textBox2.Text = "";
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.CheckState == CheckState.Checked)
{
MessageBox.Show("记住密码");
}
else
{
MessageBox.Show("取消");
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label2_Click(object sender, EventArgs e)
{
}
}
}
错误列表
错误 1 当前上下文中不存在名称“MySqlConnection”
错误 2 当前上下文中不存在名称“cmdString”
错误 3 “WindowsApplication12.Form1”并不包含“user_TB”的定义
错误 4 当前上下文中不存在名称“cmdString”
错误 5 “WindowsApplication12.Form1”并不包含“password_TB”的定义