Honestly I've tried everything and in many ways, but I can not give a simple INSERT in the database. Please could someone tell me what is wrong with this code?
using (SqlConnection con = new SqlConnection(AcessoBD.ConnectionString))
{
string queryUsuario = @"INSERT INTO si_usuario (senha, login) VALUES ('aaa', 'aaa');";
using (SqlCommand cmd = new SqlCommand(queryUsuario, con))
{
con.Open();
cmd.BeginExecuteNonQuery();
}
}
Making it clear that I've tried with:
cmd.ExecuteNonQuery();
But it did not work!
The funny thing is that I can make the bench query above using the same structure, only even changing the query. Is it a permission problem? But no error occurs!
public class AcessoBD
{
static public String ConnectionString
{
get
{
return ConfigurationManager.ConnectionStrings["Conexao"].ConnectionString;
}
}
}
Table Structure
CREATE TABLE [dbo].[si_usuario] (
[id] INT IDENTITY (1, 1) NOT NULL,
[senha] VARCHAR (100) NOT NULL,
[login] VARCHAR (100) NOT NULL,
CONSTRAINT [PK_si_usuario] PRIMARY KEY CLUSTERED ([id] ASC)
);
App.config
<add name="Conexao" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Base\Database.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />