1 year ago

#389027

test-img

Poyo

Trying to use existing code - "call a stored procedure with a parameter in c#", but can't get it working

Using the code from Call a stored procedure with parameter in c# this article.

This is my code:

using (SqlConnection con = new SqlConnection(dc.Con))
{
    using (SqlCommand cmd = new SqlCommand("sp_Add_contact", con))
    {
        cmd.CommandType = CommandType.StoredProcedure;

        cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = userName;
        cmd.Parameters.Add("@ScrambledPass", SqlDbType.VarChar).Value = encryptedPass;

        con.Open();
        cmd.ExecuteNonQuery();
    }
}

dc in the dc.Con section "does not exist in the current context" and shows an error. How do I fix this? Are there any dependencies or prerequisites I need? I already have using System.Data.SqlClient; System.Data and other basic essentials for this.

c#

sql-server

winforms

0 Answers

Your Answer

Accepted video resources