English 中文(简体)
在使用SqlCommandBuilder后,插入、删除和更新指令为无效。
原标题:Insert, Delete and Update commands are null after using SqlCommandBuilder

I have this situation where I need to modify the insert command after is generated by the sqlcommandbuilder, and I need to do this to get the scope_identity after the insert. Part of the code is :

adapterClients = new SqlDataAdapter (cmdClients, connString);
SqlCommandBuilder cmdBuilder = new SqlCommandBuilder (adapterClients);
adapterClients.Fill (dataSet, "Clients");
adapterClients.InsertCommand.CommandText += "; select ClientID = SCOPE_IDENTITY()";
adapterClients.InsertCommand.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;

I get a null exception on adapterClients.InsertCommand.

最佳回答

自动生成的“指挥”将成为建筑者而不是适应者的一部分。 因此,你想利用下面的文字来检索“指挥”:

cmdBuilder.GetInsertCommand()

因此,根据你在努力做些什么,你可以使用以下方法:(1) 规定所生成的指令给适应者,然后(2) 修改所生成的指令,以包括重新掌握范围——身份。

adapterClients.InsertCommand = cmdBuilder.GetInsertCommand();
adapterClients.InsertCommand.CommandText += "; select ClientID = SCOPE_IDENTITY()";
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签