开发者

typed-dataset initializer problem with C# windows app

Greetings,

I'm working in windows application using C#.

I have typed-dataset called packetsDBDataSet and it has table adapter called packetsTableAdapter with method to insert data called InsertPackets().

when I want to insert new data I used a code that I used before with asp.net page and it was working ok but not I'm getting error.

here is the code:

public packetsDBDataSetTableAdapters.packetsTableAdapter ds = new packetsDBDataSetTableAdapters.packetsTableAdapter();

public packetsDBDataSet.packetsDataTable insert = ds.InsertPackets(); 

and here is the error:

Error 1 A field initializer cannot reference the non-static field, method, or property 'Packets.Form1.ds' C:\Users\Ali\Documents\Visual Studio 2008\Projects\Packets-3\Packets\Packets\Form1.cs 26 59开发者_JS百科 Packets

I already included to my project: using Packets; using Packets.packetsDBDataSetTableAdapters;

please advice to solve this problem.

Update :

I also tried :

public packetsDBDataSetTableAdapters.packetsTableAdapter ds = new packetsDBDataSetTableAdapters.packetsTableAdapter();

ds.InsertPackets("1","2","3");

and I'm getting this error:

Error 1 Invalid token '(' in class, struct, or interface member declaration C:\Users\Ali\Documents\Visual Studio 2008\Projects\Packets-3\Packets\Packets\Form1.cs 28 29 Packets


These lines are called field initializers; they declare a field and initialize it to some value.

As the error says, a field initializer cannot reference instance members of the class (because they execute before the class is fully constructed).

Because it references the ds instance member, you need to move insert = ds.InsertPackets(); to the constructor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜