| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 592 人关注过本帖
标题:如何用dataGridView来写以下代码?
取消只看楼主 加入收藏
ysf0181
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:55
帖 子:914
专家分:2385
注 册:2006-10-4
结帖率:76.71%
收藏
 问题点数:0 回复次数:1 
如何用dataGridView来写以下代码?
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();
                     = sql;
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("删除专业'" + ds.Tables["specialty"].Rows[dataGrid1.CurrentCell.RowNumber][1].ToString().Trim() + "'成功", "提示");
                }
            }
        }
搜索更多相关主题的帖子: dataGridView 代码 
2008-03-29 21:18
ysf0181
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:55
帖 子:914
专家分:2385
注 册:2006-10-4
收藏
得分:0 
我自己测试好了。谢谢。。
2008-03-29 22:48
快速回复:如何用dataGridView来写以下代码?
数据加载中...
 
   



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

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