Search
 
SCRIPT & CODE EXAMPLE
 

SQL

c# execute transact sql

static public int AddProductCategory(string newName, string connString)
{
    Int32 newProdID = 0;
    string sql =
        "INSERT INTO Production.ProductCategory (Name) VALUES (@Name); "
        + "SELECT CAST(scope_identity() AS int)";
    using (SqlConnection conn = new SqlConnection(connString))
    {
        SqlCommand cmd = new SqlCommand(sql, conn);
        cmd.Parameters.Add("@Name", SqlDbType.VarChar);
        cmd.Parameters["@Name"].Value = newName;
        try
        {
            conn.Open();
            newProdID = (Int32)cmd.ExecuteScalar();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
    return (int)newProdID;
}
Comment

PREVIOUS NEXT
Code Example
Sql :: dump sql databse import export 
Sql :: To Create directory 
Sql :: check constraint is violated 
Sql :: how to create roles in oracle developer sql 
Sql :: subconjuntos SQL 
Sql :: undefined get_magic_quotes_gpc() in sqlite 
Sql :: sql save select into list 
Sql :: oracle sql add column auto generated value 
Sql :: calcul age 
Sql :: What is performance wise better join or a subquery ? 
Sql :: postgres regex word boundary 
Sql :: ring SQLite sqlite_close 
Sql :: generate sql trigger through ef migration 
Sql :: left join vs inner join performance 
Sql :: sql server 2016 iso 
Sql :: postgres docs /copy metacomand 
Sql :: oracle flush Shared Pool 
Sql :: sqlites studio red exclamation mark when poening databse 
Sql :: sqlite headers 
Sql :: Oracle Function call - 12C 
Sql :: sqlserver now 
Sql :: SQL create table full of dates 
Sql :: geopoint from json mysql function 
Sql :: look at running processes redshift 
Sql :: downlaod database mysql workbench 
Sql :: mysql where in keep order 
Sql :: what is in operator in sql 
Sql :: create table database in psql 
Sql :: sql select data from one database and insert into a different database 
Sql :: ssms keyboard shortcuts 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =