Troels Bugge

Troels Bugge

  • NA
  • 1
  • 1.2k

Passing variables to stored procedure

May 28 2013 8:58 AM
Hi,

I'm trying to pass a few variables to a stored procedure i have created in mssql. The procedure is working fine. Via my webinterface I would like to pass a few variables to the procedure but I cant seem to get it to working.

On the webinterface I have some textboxes which is first filled by a select statement. Then the user can edit the info on the webinterface and press the edit button which will update the posts in the database. The filling of the textboxes is working just fine, but if I edit some text and press edit, nothing happens in my db. Seems like nothing is passed in the procedure.

Here's the code:


[quote]

        protected void soegButton_Click(object sender, EventArgs e)
        {
            using (SqlCommand soegning = new SqlCommand(@"SP_SelectSearchUser", conn))
            {

                soegning.CommandType = CommandType.StoredProcedure;

                soegning.Parameters.Add("@userInitials", SqlDbType.VarChar).Value = soegbruger.SelectedItem.Text;

                conn.Open();
                SqlDataReader reader = soegning.ExecuteReader();

                while (reader.Read())
                {
                    editFornavn.Text = reader["fornavn"].ToString();
                    editMellemnavn.Text = reader["mellemnavn"].ToString();
                    editEfternavn.Text = reader["efternavn"].ToString();
                    editInitialer.Text = reader["initialer"].ToString();
                    editAfdeling.Text = reader["afdeling"].ToString();
                    editTelefon.Text = reader["telefonnr"].ToString();
                    editMail.Text = reader["mail"].ToString();
                    current_id = int.Parse(reader["ID"].ToString());
                }
                reader.Close();
                conn.Close();
            }


        }

        protected void edit_Click(object sender, EventArgs e)
        {
            SqlCommand editUser = new SqlCommand("SP_UpdateUser", conn);
            editUser.CommandType = CommandType.StoredProcedure;

            editUser.Parameters.Add("@firstname", SqlDbType.VarChar).Value = editFornavn.Text;
            editUser.Parameters.Add("@middlename", SqlDbType.VarChar).Value = editMellemnavn.Text;
            editUser.Parameters.Add("@lastname", SqlDbType.VarChar).Value = editEfternavn.Text;
            editUser.Parameters.Add("@initials", SqlDbType.VarChar).Value = editInitialer.Text;
            editUser.Parameters.Add("@department", SqlDbType.VarChar).Value = editAfdeling.SelectedItem.Text;
            editUser.Parameters.Add("@phonenumber", SqlDbType.VarChar).Value = editTelefon.Text;
            editUser.Parameters.Add("@mail", SqlDbType.VarChar).Value = editMail.Text;

            editUser.Parameters.Add("@currentuser_id", SqlDbType.VarChar).Value = current_id;

            conn.Open();
            editUser.ExecuteNonQuery();
            conn.Close();

            Response.Redirect(Request.RawUrl);
         }

[/quote]



I appreciate any help! :)

thanks

/Troels

Answers (1)