OSx平台下,使用SqlDataAdapter.Update方法出错。

weixin_38063872 2017-08-11 08:55:15
public int BulkToDB()
{
int res = 0;

            using (SqlConnection conn = new SqlConnection(SqlHelper.SqlConn))
            {
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    try
                    {
                        cmd.CommandText = "select * from tmpTbale where 1=2";
                        SqlDataAdapter adpt = new SqlDataAdapter(cmd);

                        DataTable dt = new DataTable();
                        adpt.Fill(dt);
                        DataRow ndr = dt.NewRow();
                        ndr[0] = 1;
                        ndr[1] = "name";
                        ndr[2] = "male";
                        dt.Rows.Add(ndr);


                        SqlCommandBuilder scb = new SqlCommandBuilder(adpt);


                        res = adpt.Update(dt);
                        dt.AcceptChanges();
                    }
                    catch (Exception ex)
                    {

                        throw ex;
                    }
                }

            }
return res;
}

以上的代码就是一个简单的将一行数据通过SqlDataAdapter.Update()方法,提交插入到数据表。相同的代码相同的数据库,在WIN平台下顺利执行插入生效。但在OSx平台(本人的MacBook Pro)使用最新的VS for Mac 的IDE工具执行这段代码后,显示如下报错:

Update requires the command clone to have a connection object. The Connection property of the command clone has not been initialized.

我不知道这是OSx平台下FrameWork的BUG,还是这个方法在OSx平台有其他的写法?不知道有没有其他朋友也遇到过这样的情况。

...全文
14 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38079736 2017-08-24
  • 打赏
  • 举报
回复
你好,
.Net Core 1.1 对SqlDBAdapter and DataTable 的支持还不够完善, 我建议你可以升级到.Net core 2.0 在试试看。
请使用Nugest 引用 System.Data.Common 和 System.Data.SqlClient
https://blogs.msdn.microsoft.com/devfish/2017/05/15/exploring-datatable-and-sqldbadapter-in-asp-net-core-2-0/
Best regards,
Cole
weixin_38069146 2017-08-22
  • 打赏
  • 举报
回复
Visual Studio Community 2017 for Mac
Version 7.1 (build 1297)

Runtime:
Mono 5.2.0.215 (d15-3/da80840) (64-bit)
GTK+ 2.24.23 (Raleigh theme)

Package version: 502000215

NuGet
Version: 4.3.0.2418

.NET Core
Runtime Versions:
1.1.1
1.0.4
SDK Version: 1.0.3

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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