开发者

Visual C# Winforms Database Problem

I am having a problem with my database problem.. errr..

INSERT INTO Customer (CustomerName)
VALUES ('Joe Schmoe'); LAST_INSERT_ID();

I used something like that in my开发者_开发技巧 winform so this statement:

  INSERT INTO Customer (CustomerName)
  VALUES ('Joe Schmoe'); LAST_INSERT_ID();

-shows me the last inserted id in my customer column

I want to store the value that I can get into a variable so that whenever I put a value to its child table (foreign key) I will use what value that I have stored in my variable to my insert statement.

How can I store it in a variable or a control?


Look at below examples. Cannot give the exact SQL without knowing your database.

SQL Server and C#: get last inserted id

Get inserted id.

How to get last inserted id?

Getting the identity of the most recently added record

C# Code Snippet - Get Identity Column Value from SQL Server

EDIT

If it is MySQL Database, you could use LAST_INSERT_ID() built in function.

Here is a code sample.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜