编程论坛's Archiver

冰冷 发表于 2008-5-9 16:02

说adb.Fill(ds, "specialty");至少有一个参数没有被指定是什么意思!!

如题  先谢大家

[[it] 本帖最后由 冰冷 于 2008-5-10 08:58 编辑 [/it]]

冰冷 发表于 2008-5-9 16:27

怎么没人呢!!!急救!!

drychq 发表于 2008-5-9 17:10

前面 的那 部分代码 了....

冰冷 发表于 2008-5-9 17:25

回复 3# 的帖子

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.OleDb;


namespace 学生专业管理系统
{
    public partial class BrowseSpecialty : Form
    {
        public BrowseSpecialty()
        {
            InitializeComponent();
        }

        OleDbConnection connection1 = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=E:\\学生专业管理.mdb");

        //定义数据集对象ds用于保存查询专业信息返回的结果集
        DataSet ds;

        //在窗口的初始化事件中,对dataGrid1进行绑定
        private void BrowseSpecialty_Load(object sender, EventArgs e)
        {
            connection1.Open();
            string sql = "select specialtyid as  编号,specialtyname as 专业名称,remark as 专业描述 from specialtyinfo";
            OleDbDataAdapter adb = new OleDbDataAdapter(sql, connection1);
            ds = new DataSet();
    0 ------ adb.Fill(ds, "specialty");----------
            dataGrid1.DataSource = ds.Tables[0].DefaultView;
        }
        //当dataGrid1中当前单元格发生变化时,将对应的专业名称显示在dataGrid1的标题中
        private void dataGrid1_CrrentCellChanged(object sender, EventArgs e)
        {
            dataGrid1.CaptionText = dataGrid1[dataGrid1.CurrentRowIndex, 1].ToString();
        }

        //点击修改按钮(button1)时,调用ModifySpecialty窗体
        private void button1_Click(object sender, EventArgs e)
        {
            ModifySpecialty modifySpecialty;
            if (dataGrid1[dataGrid1.CurrentCell] != null)
            {
                modifySpecialty = new ModifySpecialty();
                modifySpecialty.textBox1.Text = ds.Tables[0].Rows[dataGrid1.CurrentRowIndex][0].ToString().Trim();
                //获得专业编号
                modifySpecialty.textBox2.Text = ds.Tables[0].Rows[dataGrid1.CurrentRowIndex][1].ToString().Trim();
                //获得专业名称
                modifySpecialty.richTextBox1.Text = ds.Tables[0].Rows[dataGrid1.CurrentRowIndex][2].ToString().Trim();
                //获得专业描述
                modifySpecialty.ShowDialog();
                //生成新窗体
            }
        }

        //删除按钮事件
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGrid1[dataGrid1.CurrentCell] != null)
            {
                string sql = "select specialtyname from specialtyinfo where specialtyid=" + ds.Tables["specialty"].Rows[dataGrid1.CurrentCell.RowNumber][0].ToString().Trim() + "and specialtyid not in (select distinct specialtyinfo.specialtyid from classinfo inner join specialtyinfo on classinfo.specialtyname=specialtyinfo.specialtyname)";
                OleDbCommand cmd = new OleDbCommand(sql, connection1);
                OleDbDataReader dr;
                dr = cmd.ExecuteReader();
                if (!dr.Read())
                {
                    MessageBox.Show("删除专业'" + ds.Tables["specialty"].Rows[dataGrid1.CurrentCell.RowNumber][1].ToString().Trim() + "'失败,请先删除与此专业相关的班级", "提示");
                    dr.Close();
                }
                else
                {
                    dr.Close();
                    sql = "delete * from specialtyinfo where specialtyname not in (select distinct specialtyname from classinfo) and specialtyid=" + ds.Tables["specialty"].Rows[dataGrid1.CurrentCell.RowNumber][0].ToString().Trim();
                    cmd.CommandText = sql;
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("删除专业'" + ds.Tables["specialty"].Rows[dataGrid1.CurrentCell.RowNumber][1].ToString().Trim() + "'成功", "提示");
                }
            }
        }
        
        //退出
        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

         private void dataGrid1_CurrentCellChanged(object sender, EventArgs e)
        {
            dataGrid1.CaptionText = dataGrid1[dataGrid1.CurrentRowIndex, 1].ToString();
        }        
        }

    }

hebingbing 发表于 2008-5-9 18:28

你把“编号”这些换成英文呢?……

冰冷 发表于 2008-5-10 08:24

回复 5# 的帖子

string sql = "select specialtyid as  编号,specialtyname as 专业名称,remark as 专业描述 from specialtyinfo



as  前面就是它们对应的英文

冰冷 发表于 2008-5-10 09:59

那位高手指點一下!謝謝!

feel7882 发表于 2008-6-18 11:32

指定的表名称是不是不一至

feel7882 发表于 2008-6-18 11:34

fill填充的表应该跟select。。。from的表名一致。

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.