mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-03-21 07:17:15 +00:00
Export amazon settlement report fix
This commit is contained in:
49
src/bnhtrade.Core/Data/Database/Programmability/Sequence.cs
Normal file
49
src/bnhtrade.Core/Data/Database/Programmability/Sequence.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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 (string sqlConnectionString) : base(sqlConnectionString)
|
||||
{
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user