| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 405 人关注过本帖
标题:【求助】有一个C#的程序好多地方不对大家看看
只看楼主 加入收藏
天逆
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2011-6-25
结帖率:0
收藏
已结贴  问题点数:10 回复次数: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.OracleClient;
using

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        string name = null;
        string id = null;
        string job = null;
        string deptno = null;
        
        //显示信息模块的字段值
        String ename=null;
        String empnd=null;
        String ejob=null;
        String emgr=null;
        String ehiredate=null;
        String esal=null;
        String ecomm=null;
        String  edetnd=null;
        //数据库连接字符串
        String myurl = null;
        OracleConnection orclconn = null;

        public Form1()
        {
            InitializeComponent();

        }
        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }

        //插入图片
        private void picture( )
        {
           
            try
            {
                getConnection();
                orclconn.Open();
            }
            catch
            { }
            OracleCommand mycommand = orclconn.CreateCommand();
             = "insert into aa(image) values (:zp)";
            //MessageBox.Show();
            mycommand.ExecuteNonQuery();

            string imgPath = @"G:\体育\科比的照片\科比.gif ";//图片文件所在路径  
            FileStream file = new FileStream(imgPath, FileMode.Open, FileAccess.Read);
            Byte[] imgByte = new Byte[file.Length];//把图片转成 Byte型 二进制流  
            file.Read(imgByte, 0, imgByte.Length);//把二进制流读入缓冲区  
            file.Close();
        
            //mycommand.Parameters.Add("zp", System.Data.OleDb.OleDbType.Binary, imgByte.Length);
            //cmd.Parameters[0].Value = imgByte;

            try
            {
                mycommand.ExecuteNonQuery();
                MessageBox.Show("插入成功");
            }
            catch (System.Exception e1)
            {
                MessageBox.Show(e1.Message);
            }
        }  





       private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: 这行代码将数据加载到表“dataSet1.EMP”中。您可以根据需要移动或删除它。
            this.eMPTableAdapter.Fill(this.dataSet1.EMP);
            // TODO: 这行代码将数据加载到表“dataSet1.EMP”中。您可以根据需要移动或删除它。
           // this.eMPTableAdapter.Fill(this.dataSet1.EMP);

        }
        private void getConnection()
        {
            //数据库连接方法
             myurl = "Data Source=orcl;User ID=scott;Password=orcl;Integrated security=false";//连接字符串

             orclconn = new OracleConnection(myurl);//创建连接
        }

        private void sql_select()
        {

        }
        private void sql_update()
        {
            try
            {
                empnd = textBox3.Text;
                ename = textBox8.Text;
                ejob = textBox5.Text;
                emgr = textBox9.Text;
                ehiredate = textBox6.Text;
                edetnd = textBox11.Text;
                ecomm = textBox7.Text;
                esal = textBox10.Text;

                getConnection();//连接数据库
                orclconn.Open();
                OracleCommand mycommand = orclconn.CreateCommand();
                = "update emp set ename='" + ename + "', job='" + ejob + "', mgr='" + emgr + "', hiredate=to_date('" + ehiredate + "','yyyy-mm-dd hh24:mi:ss'), sal='" + esal + "', comm='" + ecomm + "', deptno='" + edetnd + "'where empno='" + empnd + "'";
                MessageBox.Show();
                mycommand.ExecuteNonQuery();
                orclconn.Close();
               
            }
            catch (Exception eq)
            {
                MessageBox.Show("有错误!!");
            }
        }
        private void sql_delete()
        {
            try
            {
                //添加新纪录
                empnd = textBox3.Text;
            
                getConnection();//连接数据库
                orclconn.Open();
                OracleCommand mycommand = orclconn.CreateCommand();
                = "delete from emp where empno='"+empnd+"'";
                mycommand.ExecuteNonQuery();
                orclconn.Close();
                // MessageBox.Show("dddddddddddd");
            }
            catch (Exception el)
            {
                MessageBox.Show("有错误!!");
            }
        }
        private void sql_insert()
        {
            try
            {
                //添加新纪录
               empnd = textBox3.Text;
                ename = textBox8.Text;
                ejob = textBox5.Text;
                emgr = textBox9.Text;
                ehiredate = textBox6.Text;
                edetnd = textBox11.Text;
                ecomm = textBox7.Text;
                esal = textBox10.Text;

                getConnection();//连接数据库
                orclconn.Open();
                OracleCommand mycommand = orclconn.CreateCommand();
                = "insert into emp values('" + empnd + "','" + ename + "','" + ejob + "','" + emgr + "','" + ehiredate + "','" + esal + "','" + ecomm + "','" + edetnd + "')";
                mycommand.ExecuteNonQuery();
                orclconn.Close();
                // MessageBox.Show("dddddddddddd");
            }
            catch(Exception el)
            {
                MessageBox.Show("有错误!!");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //普通查询
            try
            {
                 String sql = "select * from emp where ";
                 name = textBox1.Text;
                 id = textBox2.Text;
                 if(comboBox1.Text!="")
                 job = comboBox1.SelectedItem.ToString();
                 if (comboBox1.Text != "")
                 deptno = comboBox1.SelectedItem.ToString();

                 if (name == "" && id == "" && job == null && deptno == null)
                     MessageBox.Show("请输入查询条件");
                 else
                 {
                     getConnection();//连接数据库

                     if (name != "")
                         sql = String.Concat(sql, "ename='" + name + "'and ");
                     if (id != "")
                         sql = String.Concat(sql, "empnd='" + id + "'and ");
                     if (job != null)
                         sql = String.Concat(sql, "job='" + job + "'and ");
                     if (deptno != null)
                         sql = String.Concat(sql, "edetnd='" + deptno + "'");
                     else
                         sql = sql.Remove(sql.Length - 4);

                     orclconn.Open();
                     MessageBox.Show(sql);
                     // OracleTransaction mytansaction = orclconn.BeginTransaction();//开始事务

                     // OracleCommand mycommand = orclconn.CreateCommand();//创建sql命令变量

                     DataTable table = new DataTable();
                     OracleDataAdapter myadapter = new OracleDataAdapter(sql, orclconn);

                     myadapter.Fill(table);

                     dataGridView1.DataSource = table;
                     
                     // ();//提交事务
                     orclconn.Close();//关闭数据库连接  
                 }
            }
            catch (Exception ew)
            {
                MessageBox.Show("有错误!!");
            }
     
        }

        private void button6_Click(object sender, EventArgs e)
        {
            //语句查询
            try
            {
                String input_sql = textBox4.Text;
                if (input_sql != "")
                {
                    getConnection();//创建连接

                    orclconn.Open();

                    DataTable table2 = new DataTable();

                    OracleDataAdapter myadapter = new OracleDataAdapter(input_sql, orclconn);

                    myadapter.Fill(table2);

                    dataGridView1.DataSource = table2;

                    orclconn.Close();//关闭数据库连接
                    // MessageBox.Show(input_sql);
                }
                else
                { MessageBox.Show("请输入SQL语句!"); }

            }
            catch (Exception ew)
            {
                MessageBox.Show("输入有错误!!");
            }
            
        }
        private void displayInfo()
        {
            //int i = dataGridView1.CurrentCell.RowIndex;
         
            empnd = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            ename = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            ejob = dataGridView1.CurrentRow.Cells[2].Value.ToString();
            emgr = dataGridView1.CurrentRow.Cells[3].Value.ToString();
            ehiredate = dataGridView1.CurrentRow.Cells[4].Value.ToString();
            esal = dataGridView1.CurrentRow.Cells[5].Value.ToString();
            ecomm = dataGridView1.CurrentRow.Cells[6].Value.ToString();
            edetnd = dataGridView1.CurrentRow.Cells[7].Value.ToString();

           textBox8.Text=ename;
           textBox3.Text=empnd;
           textBox5.Text=ejob;
           textBox9.Text=emgr;
           textBox6.Text= ehiredate;
           textBox11.Text=edetnd;
           textBox7.Text=ecomm;
           textBox10.Text=esal;

          // MessageBox.Show(i+ename);

        }

        private void button2_Click(object sender, EventArgs e)
        {
            //添加新行
            sql_insert();
        }

        private void haha(object sender, DataGridViewCellEventArgs e)
        {
         //单击表单事件   
           displayInfo();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            //修改
            sql_update();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //删除
            sql_delete();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //取消
           DialogResult result= MessageBox.Show("确定退出?","请确认",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2);
           if (result == DialogResult.Yes)
               Application.Exit();
           else
               return;

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
        
        }

        private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
        
        }
    }
}


2011-06-26 21:58
赵丹
Rank: 2
等 级:论坛游民
帖 子:5
专家分:16
注 册:2011-4-26
收藏
得分:3 
围观,待楼下高手解答

[url=http://t./p/u/141487987]5万元创业项目[/url]
2011-06-27 14:16
girl0001
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:56
专家分:118
注 册:2010-7-17
收藏
得分:3 
也说下哪里不对啊,这怎么改啊?
2011-06-27 20:48
dwwwing
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:1
帖 子:284
专家分:986
注 册:2008-10-11
收藏
得分:3 
你最好说明你想改什么方面,这样比较方便
2011-06-27 21:42
快速回复:【求助】有一个C#的程序好多地方不对大家看看
数据加载中...
 
   



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

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