c#添加问题?

zhjdelphi 2008-07-14 11:12:41
MySqlDataAdapter = MyFunction.GetSqlDataAdapter("SELECT distinct college from college where college='" + comboBox1.Text.ToString().Trim() + "'");
MySqlDataAdapter.Fill(MyDataSet , "college");
if (MyDataSet.Tables["college"].Rows.Count > 0)
{
MessageBox.Show("同名学院已存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}

我这个为什么只能添加一条再添加一条(不一样)也弹出同名学院已存在


明明学院aa
不存在我调试查了下

MyDataSet.Tables["college"].Rows.Count =1?
为什么啊 ?
...全文
57 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhjdelphi 2008-07-14
  • 打赏
  • 举报
回复
晕,原来是这个问题啊
谢谢了
cnjimbo 2008-07-14
  • 打赏
  • 举报
回复
MySqlDataAdapter = MyFunction.GetSqlDataAdapter("SELECT distinct college from college where college='" + comboBox1.Text.ToString().Trim() + "'");
MyDataSet = New DataSet();
MySqlDataAdapter.Fill(MyDataSet , "college");
if (MyDataSet.Tables["college"].Rows.Count > 0)
{
MessageBox.Show("同名学院已存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
huguang2yq 2008-07-14
  • 打赏
  • 举报
回复
MyDataSet.Tables["college"].Rows.Count > 0
这个判断.......如果行数大于0,就执行下面的..
你已经添加了一条,肯定不能再添加啦.....晕...
billclinton8 2008-07-14
  • 打赏
  • 举报
回复
MySqlDataAdapter = MyFunction.GetSqlDataAdapter("SELECT college from college where college='" + comboBox1.Text.ToString().Trim() + "'");
MyDataSet.Clear();
MySqlDataAdapter.Fill(MyDataSet , "college");
if (MyDataSet.Tables["college"].Rows.Count > 0)
{
MessageBox.Show("同名学院已存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
初吻给了烟 2008-07-14
  • 打赏
  • 举报
回复
MySqlDataAdapter.Fill(MyDataSet , "college"); 是往里面追加的,改成局部变量就可以了
初吻给了烟 2008-07-14
  • 打赏
  • 举报
回复
因你的MyDataSet 不是局部变量,改成局部变量
grearo 2008-07-14
  • 打赏
  • 举报
回复
MySqlDataAdapter = MyFunction.GetSqlDataAdapter("SELECT distinct college from college where college='" + comboBox1.Text.ToString().Trim() + "'");
MyDataSet.Clear();
MySqlDataAdapter.Fill(MyDataSet , "college");
if (MyDataSet.Tables["college"].Rows.Count > 0)
{
MessageBox.Show("同名学院已存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}

110,043

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧