czwartek, 3 lipca 2008

Kiedy są problemy z ID

11.10.2007 at 01:43AM PST, ID: 20255081

Rank: Sage

Sorry, my mistake. Scope-identity doesn't work with acces

Did you try SELECT @@IDENTITY

Example
public Client CreateClient( string name )
{
OleDbCommand command = null;
Client c = new Client();
c.Name = name;

try
{
command = Connection.CreateCommand()
;
command.CommandText = "insert into Clients (name) values(@name)";
command.Parameters.Add("@name",name);
command.ExecuteNonQuery();
// Retrieve ID
command.CommandText = "SELECT @@IDENTITY";
c.ID = Int64.Parse(command.ExecuteScalar().ToString());
return c;
}
finally
{
command.Dispose();
}

Brak komentarzy: