SqlDataAdapter.update在if块问题之外 [英] SqlDataAdapter.update outside the if block problem

查看:100
本文介绍了SqlDataAdapter.update在if块问题之外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个插入语句,并且希望在if语句之外执行插入,如下所示:

I have an insert statement and I want the insertion to be performed outside the if statement like this:

if(something)

{ 字符串行= Console.ReadLine(); 正则表达式r =新的正则表达式("[] +"); 字符串[]字段= r.Split(line); table = ds.Tables [0]; DataRow nr = table.NewRow(); nr.BeginEdit(); nr ["t#"] = fields [0]; nr ["tn"] = fields [1]; nr [" tc] = fields [2]; nr.EndEdit(); table.Rows.Add(nr); SqlCommandBuilder b =新的SqlCommandBuilder(ad); } 否则,(其他) { ad.Update(table); }

{ string line = Console.ReadLine(); Regex r = new Regex("[ ]+"); string[] fields = r.Split(line); table = ds.Tables[0]; DataRow nr = table.NewRow(); nr.BeginEdit(); nr["t#"] = fields[0]; nr["tn"] = fields[1]; nr["tc] = fields[2]; nr.EndEdit(); table.Rows.Add(nr); SqlCommandBuilder b = new SqlCommandBuilder(ad); } else if (somethingelse) { ad.Update(table); }

但是更新没有执行.

有人可以帮我吗?谢谢

推荐答案

你好

如果触发了"if(somethingelse)",则将跳过"else if(somethingelse)". 直接.这意味着只能执行其中之一,否则将无法执行.

If the "if(something)" is fired, then the "else if (somethingelse)" will be skipped  directly. That means only one of them can be executed or both of them would not be executed.

如果"else if(somethingelse)"被触发,则不修改表实例,这应该在上面的语句中进行,当然,它不会更新数据库.

If "else if(somethingelse)" is fired, then the table instace is not be modified which should be done in the above statement, of course, it will not update the database.

所以您需要将它们放在一起.

So you need to put them together.

此致.


这篇关于SqlDataAdapter.update在if块问题之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆