Wednesday, November 10, 2021

Stored procedure in asp.net C#

private void button1_Click(object sender, EventArgs e) {

String conStr = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;

  using (SqlConnection con = new SqlConnection(conStr )) {

    using (SqlCommand cmd = new SqlCommand("sp_Add_contact", con)) {

      cmd.CommandType = CommandType.StoredProcedure;


      cmd.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = txtFirstName.Text;

      cmd.Parameters.Add("@LastName", SqlDbType.VarChar).Value = txtLastName.Text;


      con.Open();

      cmd.ExecuteNonQuery();

con.close();

    }

  }


---------------------********************---------------------

<configuration>

<connectionStrings>

<add name="connectionString" connectionString="initial catalog=aggregate;user=sa1;password=sa;data source=." />

<add name="connectionStringTest" connectionString="initial catalog=test;user=sa1;password=sa;data source=." />

</connectionStrings>


</configuration>

No comments:

Post a Comment