Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public bool AddNewCustomer(string Name, ref int NewIdentifier)
- {
- using (SqlConnection cn = new SqlConnection { ConnectionString = Properties.Settings.Default.ConnectionString })
- {
- using (SqlCommand cmd = new SqlCommand { Connection = cn })
- {
- cmd.CommandText = "INSERT INTO [Customer] (CompanyName) VALUES (@CompanyName); SELECT CAST(scope_identity() AS int);";
- cmd.Parameters.AddWithValue("@CompanyName", Name);
- cn.Open();
- try
- {
- NewIdentifier = Convert.ToInt32(cmd.ExecuteScalar());
- return true;
- }
- catch (Exception)
- {
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement