使用SQLDataAdapter的填充方法(断开连接模式)时获取查询状态? [英] Getting query status while using SQLDataAdapter's Fill Method(Disconnected Mode)?

查看:126
本文介绍了使用SQLDataAdapter的填充方法(断开连接模式)时获取查询状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个基本的简单问题,我试图在我尝试向行中插入行时获取查询执行结果数据库使用dataadapter的填充方法。

我知道我可以使用连接模式SqlCommand的ExecuteNonQuery方法实现相同的目标。

但是我不想这样做,有没有机会我可以得到结果是否已插入数据库或不使用dataadapter的填充方法..

以下是我的代码。



< pre lang =cs> 使用(SqlDataAdapter da = new SqlDataAdapter( SomeInsertQuery))
{
使用 (DataSet ds = new DataSet())
{

da.Fill(ds);
// 这里我需要检查插入是否成功,以便我可以显示正确的错误消息。 ..

if (!String.IsNullOrEmpty(successMsg))
{
PSVMsgBox.ShowDALMsgBox (successMsg);
}

}
}
感谢 提前。

解决方案

你应该使用 DbDataAdapter.Update方法(数据集) [ ^ ]而不是填充

引用:

返回值

类型:System.Int32

从<$成功更新的行数C $ C>数据集


Hi All,

I have a basic simple problem,i am trying to get the result of query executed or not when i try to insert a row into the database using dataadapter's fill method.
I know i can achieve the same using Connected Mode SqlCommand's ExecuteNonQuery method.
But i do not want to do that way , Is there any chance that i can get the result whether row has inserted into database or not using dataadapter's fill method ..
Below is my code.

using (SqlDataAdapter da = new SqlDataAdapter("SomeInsertQuery"))
{
  using (DataSet ds = new DataSet())
   {
                                        
    da.Fill(ds);
//here i need to check whether insertion is successful or not so that i can display proper error message...

    if (!String.IsNullOrEmpty(successMsg))
    {  
      PSVMsgBox.ShowDALMsgBox(successMsg);
    }
                                        
   }
}
Thanks in Advance.

解决方案

You should use DbDataAdapter.Update Method (DataSet)[^] instead of Fill.

Quote:

Return Value
Type: System.Int32
The number of rows successfully updated from the DataSet.


这篇关于使用SQLDataAdapter的填充方法(断开连接模式)时获取查询状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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