string ConnString = System.Configuration.ConfigurationManager.ConnectionStrings["MysqlConnectionString"].ToString();
string sql = "";
MySqlConnection
conn
= new MySqlConnection(ConnString);
MySqlCommand
cmd
= new MySqlCommand();
MySqlDataAdapter
da
= new MySqlDataAdapter();
cmd.Connection = conn;
sql = "INSERT INTO table (var1,var2) VALUES (@v1,@v2);SELECT LAST_INSERT_ID()";
cmd.CommandText = sql;
da.SelectCommand = cmd;
da.SelectCommand.Parameters.AddWithValue("@v1", 1);
da.SelectCommand.Parameters.AddWithValue("@v2", "AA");
DataTable dt = new DataTable();
da.Fill(dt);
last_insert_id = dt.Rows[0][0].ToString();
沒有留言:
張貼留言