标题:如何用dataGridView来写以下代码?
只看楼主
ysf0181
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:55
帖 子:914
专家分:2385
注 册:2006-10-4
结帖率:76.71%
 问题点数:0 回复次数:2 
如何用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
师妃暄
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:805
专家分:107
注 册:2006-3-1
得分:0 
恭喜恭喜

有实力才会有魅力 实力来自坚持不懈的努力
2008-03-30 02:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-206072-1-1.html




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

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