Return ID from SQL SET
This commit is contained in:
@@ -55,7 +55,7 @@ namespace BoredCareers.Services.DatabaseService {
|
|||||||
return company;
|
return company;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SetCompany( Company company ) {
|
public async Task<int> SetCompany( Company company ) {
|
||||||
using (MySqlConnection connection = GetConnection()) {
|
using (MySqlConnection connection = GetConnection()) {
|
||||||
connection.Open();
|
connection.Open();
|
||||||
|
|
||||||
@@ -76,6 +76,8 @@ namespace BoredCareers.Services.DatabaseService {
|
|||||||
StateOrRegion = @StateOrRegion,
|
StateOrRegion = @StateOrRegion,
|
||||||
City = @City,
|
City = @City,
|
||||||
Description = @Description;
|
Description = @Description;
|
||||||
|
|
||||||
|
Select LAST_INSERT_ID();
|
||||||
";
|
";
|
||||||
|
|
||||||
MySqlCommand cmd = new MySqlCommand(command, connection);
|
MySqlCommand cmd = new MySqlCommand(command, connection);
|
||||||
@@ -92,7 +94,9 @@ namespace BoredCareers.Services.DatabaseService {
|
|||||||
cmd.Parameters.AddWithValue("@City", company.City);
|
cmd.Parameters.AddWithValue("@City", company.City);
|
||||||
cmd.Parameters.AddWithValue("@Description", company.Description);
|
cmd.Parameters.AddWithValue("@Description", company.Description);
|
||||||
|
|
||||||
await cmd.ExecuteNonQueryAsync();
|
object? result = await cmd.ExecuteScalarAsync();
|
||||||
|
int insertedId = result != null ? Convert.ToInt32(result) : 0;
|
||||||
|
return insertedId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user