Get AutoIncrement Value For A New Record

If your table has a column  that is auto assigned a value when a record is created, e.g. an autoincrement ID value, you can get it using scope_iendity() as follows: int RecordId; SqlCommand1->CommandType = CommandType::Text; SqlCommand1->CommandText = "INSERT INTO MyTable (SomeRow1, SomeRow2) VALUES (@MyValue1, @MyValue2); SELECT CAST(scope_identity() AS int)"; SqlCommand1->Parameters->AddWithValue("@MyValue1", MyValue1); SqlCommand1->Parameters->AddWithValue("@MyValue2", Convert::ToString(MyValue2)); RecordId = (Int32)SqlCommand1->ExecuteScalar(); //ExecuteScalar […]

Read More

General Insert Statements

Insert New Row (Record) Into A Table “INSERT INTO SomeTableName (SomeColumnName1, SomeColumnName2, SomeColumnName3) VALUES (” + Convert::ToString(ColumnValue1) + “, ” + Convert::ToString(ColumnValue2) + “, \'” + ColumnValue3 + “\’)”; In this example ColumnValue1 and ColumnValue2 are numbers and column value 3 is a string

Read More