David, te envio este codigo a mi me funciona perfectamente, la verdad yo pase por este problema, espero te funcione....
static private string GetConnectionString()
{
// To avoid storing the connection string in your code,
// you can retrieve it from a configuration file, using the
// System.Configuration.ConfigurationSettings.AppSettings property
return "Data Source=PFP-PC\sqlexpress;Initial Catalog=db_inventario_pfp;"
+ "Integrated Security=SSPI;";
}
private void button1_Click(object sender, EventArgs e)
{
string connectionString = GetConnectionString();
if (textCodigo .Text=="" )
{
MessageBox.Show("Código de mesero no puede ser blanco");
}
else if (textNombre.Text == "")
{
MessageBox.Show("Nombre de mesero no puede ser blanco");
}
else {
/* MessageBox.Show(connectionString );*/
using (SqlConnection connection = new SqlConnection(connectionString))
{
int nempresa;
nempresa = 1;
connection.Open();
/*creo el comand y seteo sus propiedades*/
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "sp_agrega_mesero";
command.CommandType = CommandType.StoredProcedure;
/*define el ingreso de parametros*/
SqlParameter parametros = new SqlParameter();
command.Parameters.Add(new SqlParameter("@id_empresa", nempresa));
command.Parameters.Add(new SqlParameter("@id_mesero", textCodigo.Text));
command.Parameters.Add(new SqlParameter("@nombre_mesero", textNombre.Text));
command.ExecuteNonQuery();
textCodigo.Text = "";
textNombre.Text = "";
MessageBox.Show("proceso termino satisfactoriamente");
/* MessageBox .Show ("ServerVersion: {0}", connection.ServerVersion);
MessageBox .Show ("State: {0}", Convert.ToString( connection.State) );
MessageBox.Show("Proceso insercion termino satisfasctorimente");
*/
connection.Close();
/*listBox1.DataSource = null;
listBox1.DataSource = splistameseroBindingSource;
listBox1.DisplayMember = "Nombre_mesero";*/
}
}
listBox1.Refresh();
}