| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 654 人关注过本帖
标题:C# 登录界面代码 编译时老说数据类型问题 求教
只看楼主 加入收藏
又见根号三
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2011-6-2
结帖率:0
收藏
 问题点数:0 回复次数:3 
C# 登录界面代码 编译时老说数据类型问题 求教
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.OleDb;

namespace jsglxt
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;data source=dl.mdb");

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string strName = textBox1.Text;
            string strPwd = textBox2.Text;
            string strRole = comboBox1.Text;
            string strOleDb = null;
            
            if (strRole == "学生")
            {
                strOleDb = "SELECT * From 登录 WHERE flag=2 AND Username='" + strName + "' AND password='" + strPwd + "'";
            }
            else if (strRole == "教师")
            {
                strOleDb = "SELECT * From 登录 WHERE flag=1 AND Username='" + strName + "' AND password='" + strPwd + "'";
            }
            else if (strRole == "管理员")
            {
                strOleDb = "SELECT * From 登录 WHERE flag=0 AND Username='" + strName + "' AND password='" + strPwd + "'";
            }
            else
            {
                MessageBox.Show("请选择用户类型");
                return;
            }

            OleDbCommand cmd = new OleDbCommand(strOleDb, conn);
            conn.Open();
            OleDbDataReader reader = cmd.ExecuteReader();

            if (reader.Read())
            {
                if (comboBox1.Text == "学生")
                {
                    Form2 studentform = new Form2();
                    //studentform.setStateName(strName);
                    studentform.Show();
                    ;
                    this.Visible = false;
                }
                if (comboBox1.Text == "教师")
                {
                    Form2 teacherform = new Form2();
                    //adminform.setStateName(strName);
                    teacherform.Show();
                    ;
                    this.Visible = false;

                }
                if (comboBox1.Text == "管理员")
                {
                    Form3 adminform = new Form3();
                    //adminform.setStateName(strName);
                    adminform.Show();

                    this.Visible = false;
                }
            }
            else
            {
                MessageBox.Show("用户名或密码错误!");
            }
        }

    }
}
编译说数据类型不对  不知道为什么  我用的Access数据库(.mdb) OleDbCommand cmd = new OleDbCommand(strOleDb, conn);编译时这句话出现上述错误   数据类型没有错啊
搜索更多相关主题的帖子: private 
2011-06-10 00:19
gonghengman
Rank: 1
来 自:北京,中关村
等 级:新手上路
帖 子:2
专家分:7
注 册:2011-6-10
收藏
得分:0 
OleDbCommand cmd = new OleDbCommand(strOleDb, conn);你这句话得到的什么数据连接对象?OleDbCommand cmd = new OleDbCommand(strOleDb, conn);你这句话得到的什么数据连接对象?
2011-06-10 10:04
slb00814
Rank: 2
来 自:黑龙江
等 级:论坛游民
帖 子:41
专家分:47
注 册:2008-11-2
收藏
得分:0 
回复 2楼 gonghengman
看这个写法应该是oracle的链接

曾经沧海,除却巫山。
2011-06-10 10:07
dwwwing
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:284
专家分:986
注 册:2008-10-11
收藏
得分:0 
我vs2010编译上述代码无异常
2011-06-10 10:22
快速回复:C# 登录界面代码 编译时老说数据类型问题 求教
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.042449 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved