mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-19 14:37:16 +00:00
50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SqlClient;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace bnhtrade.Core.Data.Database.Programmability
|
|
{
|
|
public class Sequence : Connection
|
|
{
|
|
public Sequence ()
|
|
{
|
|
|
|
}
|
|
public int GetNext(string sequenceName)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(sequenceName))
|
|
{
|
|
throw new Exception("Sequence name is null or whitespace.");
|
|
}
|
|
|
|
using (SqlConnection conn = new SqlConnection(SqlConnectionString))
|
|
{
|
|
conn.Open();
|
|
|
|
using (SqlCommand cmd = new SqlCommand(@"
|
|
SELECT NEXT VALUE FOR " + sequenceName
|
|
, conn))
|
|
{
|
|
//cmd.Parameters.AddWithValue("@sequenceName", sequenceName);
|
|
// it wouldn't let me use parameters
|
|
|
|
object obj = cmd.ExecuteScalar();
|
|
|
|
try
|
|
{
|
|
//string whaaaat = (string)obj;
|
|
return Convert.ToInt32(obj);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw new Exception("Error returning next value in sequence: " + ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|