已有56人关注
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”的定义





分享到:
精彩评论 1
小科_mrkj
学分:43 LV2
2010-07-07
沙发
读者朋友:
    您好,MySqlConnection和cmdString是变量名称,但你没有声明,所以出现问题;user_TB和password_TB是控件名称,你的窗体中没有这两个控件,所以出现问题。建议你好好学一些C#基础再做程序,你问的这些都是最基础的问题。
首页上一页 1 下一页尾页 1 条记录 1/1页
手机同步功能介绍
友情提示:以下图书配套资源能够实现手机同步功能
明日微信公众号
明日之星 明日之星编程特训营
客服热线(每日9:00-17:00)
400 675 1066
mingrisoft@mingrisoft.com
吉林省明日科技有限公司Copyright ©2007-2022,mingrisoft.com, All Rights Reserved长春市北湖科技开发区盛北大街3333号长春北湖科技园项目一期A10号楼四、五层
吉ICP备10002740号-2吉公网安备22010202000132经营性网站备案信息 营业执照