English 中文(简体)
自动确定新数据集中的外国钥匙和自动编号?
原标题:Automatically setting foreign keys & autonumbers in new DataGridView rows?

1. 我的指令表如下:

orderid, clientid, [columns for order details] ...

然后,我用数据GridView向特定客户显示这一表格。 页: 1 但是,由于<代码>orderid是自动编号的主要钥匙,clientid是固定的。

不幸的是,在数据Grid意见中添加新行时,这些新行并不坚持到数据库中。 我认为,这是因为,每当数据GridView插入新行时,orderid<-1>>和/或clientidnull的缺省,但由于这些栏目隐藏在用户手中,无法更改。

So,我的问题:

如果插入新的行文,我如何能够自动选择<代码>clientid/code>对目前展示的客户违约?

最佳回答

看来,我可以把用户“Add子”活动捉trap见肘,人工确定正确的价值:

private void myDataGridView_UserAddedRow(object sender, DataGridViewRowEventArgs e)
{
    myDataGridView[clientidColumn.Index, e.Row.Index - 1].Value = clientid;
}

现在,这种新订单一直维持在数据库中,尽管似乎只是一种比照的黑体(需要打e.Row.Index - 1?)。 难道没有办法规定新行各栏的缺省值?

问题回答

您可能希望建立一个硕士/详细表格。





相关问题
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. ...