取出當前新增資料的索引。
語法如下:
string sql = "insert into pictures_annotation (pictures_annotation_top,pictures_annotation_left,pictures_annotation_width,pictures_annotation_height,pictures_annotation_text,pictures_annotation_pid,pictures_annotation_username,pictures_annotation_date)values(@top,@left,@width,@height,@text,@pid,@username,@date);select @NewPK = @@IDENTITY";
this.sqlConn.Open();
this.sqlCmd = new SqlCommand(sql, this.sqlConn);
this.sqlCmd.Parameters.Add("top", SqlDbType.Int).Value = (int)Convert.ToDouble(top);
this.sqlCmd.Parameters.Add("left", SqlDbType.Int).Value = (int)Convert.ToDouble(left);
....
.......省略
SqlParameter pkPara = new SqlParameter("NewPK",SqlDbType.Int);
pkPara.Direction = ParameterDirection.Output;
this.sqlCmd.Parameters.Add(pkPara);
this.sqlCmd.ExecuteNonQuery();
this.sqlConn.Close();
//get current aid
aid = this.sqlCmd.Parameters["NewPK"].Value.ToString();
沒有留言:
張貼留言
留個話吧:)