Hi,
First of all, sorry for my english!
I have a bug with Insert BuisinessBase object. When i insert object, I read the Id with the OUTPUT parameter and assign the value to local variable _Id. Every think is ok...
--- There is my DataPortal_Insert...
[Transactional(TransactionalTypes.TransactionScope)]
protected override void DataPortal_Insert()
{
using (SqlConnection cn = new SqlConnection(Database.GetConnection))
{
cn.Open();
using (SqlCommand cm = cn.CreateCommand())
{
cm.CommandText = "UsersInsert";
cm.CommandType = CommandType.StoredProcedure;
cm.Parameters.AddWithValue("@Username", _Username);
cm.Parameters.AddWithValue("@Password", _Password);
cm.Parameters.AddWithValue("@FirstName", _FirstName);
cm.Parameters.AddWithValue("@LastName", _LastName);
SqlParameter param = new SqlParameter("@Id", SqlDbType.Int);
param.Direction = ParameterDirection.Output;
cm.Parameters.Add(param);
cm.ExecuteNonQuery();
_Id = (int)cm.Parameters["@Id"].Value;
}
}
}
The Problem is when i'm using this class, i do something like :
User = User.NewUser();
User.Firstname = "...."
User.Save();
After the Save(), the Id of the object is ALWAYS 0, i try to put the _Id to a other variable but i do the same think!
Thanks a lot for you help!
Simon
User = User.NewUser();
User.Firstname = "...."
//This line of code is wrong:
User.Save();
//It should be:
User = User.Save();
Remember, the DataPortal returns a new instance of the object to the UI which includes the new ID value you just created.
Joe
Ho!
Thanks a LOT, that the solution ;)
Thanks
Simon
Copyright (c) Marimer LLC