0
최근 MySQL 데이터 어댑터를 v5에서 v6으로 업그레이드했습니다. v5 MySQL 데이터 어댑터를 사용할 때 아래 코드는 완벽하게 작동했습니다. 그러나 데이터 어댑터의 v6을 사용하기 시작한 이래로 새 레코드를 추가하면 레코드의 "새로운"ID가 반환되지 않습니다. 누구든지 이것을 달성하기위한 우아한 방법을 알고 있습니까?MySQL 데이터 어댑터 버전 6.1.3.0이 ver 5 데이터 어댑터 작동시 ID를 반환하지 않습니다.
protected void SetRecord(ref T Data, string Sql)
{
//
// Get a connection to use
//
string connectionKey = "";
MySqlConnection Connection = ConnectionManager.Current.OpenConnection(out connectionKey);
MySqlDataAdapter da;
MySqlCommandBuilder cb;
DataTable dt = new DataTable();
DataRow dr;
da = new MySqlDataAdapter(Sql, Connection);
da.Fill(dt);
//
// If there is more than one row, then edit 1st row, else add new row
//
if (dt.Rows.Count > 0)
{
dr = dt.Rows[0];
DatabaseRow_Set(ref dr, Data);
//
// Update the DataSet with the Database
//
cb = new MySqlCommandBuilder(da);
da.Update(dt);
}
else
{
dr = dt.NewRow();
DatabaseRow_Set(ref dr, Data);
dt.Rows.Add(dr);
//
// Update the DataSet with the Database
//
cb = new MySqlCommandBuilder(da);
da.Update(dt);
//
// Call get from data row to get new ID
//
DatabaseRow_Get(dr, ref Data);
}
//
// Close Connection
//
ConnectionManager.Current.CloseConnection(connectionKey);
}