也就是用c#做个登陆,要求是登陆界面的用户名和密码要求检查Oracle数据库理有没有相应的字段 而且已经在数据库里建表了表的名称是denglu,只需要分别判断字段user和password中存的信息跟textbox1和textbox2中输入的是否跟数据库中的相等
然后在登录 代码如下:
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.OracleClient;namespace WindowsFormsApplication4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void enter()
        {
            string name = textBox1.Text;
            string password = textBox2.Text;            if (name == "" || password == "")
            {
                MessageBox.Show("用户名和密码不能为空!");
            }
        }        private void button1_Click(object sender, EventArgs e)
        {
            string constring = "data source=oracle;user=yjk;password=manager;";//定义连接数据库的字符串
            OracleConnection conn = new OracleConnection(constring);//进行连接            conn.Open();//打开指定的连接
            OracleCommand com = conn.CreateCommand();
            com.CommandText = "select count(*) from denglu where usere='" + textBox1.Text.Trim() + "' and password='" + textBox2.Text.Trim() + "'"; //where USERE='1'"写好想执行的Sql语句
            OracleDataReader odr = com.ExecuteReader();//创建一个OracledataReader对象
            odr = com.ExecuteReader();
            string a1 = textBox1.Text;
            string a2 = textBox2.Text;
            com.Connection = conn;
            com.CommandText = com.ToString();
            MDIParent1 child = new MDIParent1();
            try
            {
                if (com.ExecuteNonQuery() == 0)//读取数据,如果返回为false的话,就说明到记录集的尾部了
                {                    MessageBox.Show("您的用户名或密码错误!");                }
                else                    child.Show();
                this.Hide();
                odr.Close();//关闭reader.这是一定要写的
            }
            catch
            {
                MessageBox.Show("erro");//如果发生异常,则提示出错
            }
            finally
            {
                conn.Close();//关闭打开的连接
            }        }        private void Form1_Load(object sender, EventArgs e)
        {
            this.AcceptButton = button1;
            this.CenterToScreen();
        }        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
        
            }我是纯新手 很多地方有点乱 也不知所以 还望高手不吝赐教啊 谢谢了!

解决方案 »

  1.   


    string ConnectionString = "server=fp;uid=fp_db;pwd=sa;data source=fp";
            private void btnLogin_Click(object sender, EventArgs e)
            {            OracleConnection conn = new OracleConnection(ConnectionString);            conn.Open();//打开连接
                OracleCommand scd = new OracleCommand("select * from owner where username='" + textBox1.Text.Trim() + "' and password='" + textBox2.Text.Trim() + "'", conn);
                OracleDataReader sdr = scd.ExecuteReader();//读取数据
                if (sdr.Read())  
                {
                    M_str_name = textBox1.Text;
                    M_str_pwd = textBox2.Text.Trim();                F_Main main = new F_Main();
                    main.Show();
                    this.Hide();
                    
                }
                    
                else
                {
                    MessageBox.Show("用户名或密码错误!");
                }
                conn.Close();           
                
           }
    这是我的ORACLE登录。请参考