0

LAST_INSERT_ID()WebMatrix で MySQL データベースを使用する方法がわかりません。以下のコード スニペットに適用する方法を教えてもらえますか?

var clothingsize="";
if(IsPost){     
clothingsize =Request["clothingsize"];         

var SQLINSERT = "INSERT INTO fit1 (clothingsize) VALUES (@0)"; }
4

2 に答える 2

0

MySQL .NET Connector を使用していると思いますか?

http://dev.mysql.com/downloads/connector/net

もしそうなら、ここにあなたが探しているものの非常に簡単な例があります:

http://forums.mysql.com/read.php?38,98672,98868#msg-98868

Insert-Command を実行した後 (C#、接続は conDBConnection に保存されます):

> string strSQLSelect = "SELECT @@IDENTITY AS 'LastID'"; 
> MySqlCommand dbcSelect = new MySqlCommand(strSQLSelect,
> conDBConnection);  MySqlDataReader dbrSelect =
> dbcSelect.ExecuteReader(); 
> 
> dbrSelect.Read();  int intCounter =
> Int32.Parse(dbrSelect.GetValue(0).ToString()); 
> 
> dbrSelect.Dispose();  conDBConnection.Close();

ハッピーコーディング!

于 2011-12-23T04:46:23.160 に答える
0

機能するソリューションは次のとおりです。

サインアップページのこのコードの直後

db.Execute(SQLINSERT, fname, lname);

次の 2 行のコードを追加します。

var customer_info_user_id = db.GetLastInsertId(); 
Response.Redirect("~/fit.cshtml?customer_info_user_id=" + customer_info_user_id);

次に、後続のページに次を挿入します。

データベースを開く変数の前

var customer_info_user_id = Request["customer_info_user_id"];

INSERT 関数に引き継がれた ID 番号を追加します。例えば:

var SQLINSERT = "INSERT INTO fit (customer_info_user_id, clothingsize) VALUES (@0,@1)";                  
db.Execute(SQLINSERT, customer_info_user_id, clothingsize);

ID番号を次のページに引き継ぐ

Response.Redirect("~/flatter.cshtml?customer_info_user_id=" + customer_info_user_id);

これを理解するのを手伝ってくれた @Mike Brind と ASP.net フォーラムに感謝します :-)

于 2012-07-26T02:30:00.883 に答える