Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code........


C#
public partial class SP : System.Web.UI.Page
{
   
    SqlConnection con;
    //Here we declare the parameter which we have to use in our application
    SqlCommand cmd = new SqlCommand();
    SqlParameter sp1 = new SqlParameter();
    SqlParameter sp2 = new SqlParameter();
    SqlParameter sp3 = new SqlParameter();
    SqlParameter sp4 = new SqlParameter();

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnsub_Click(object sender, EventArgs e)
    {
        con = new SqlConnection("Data Source=..... Catalog=.......;Integrated Security=True");
        cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = TextBox1.Text;
        cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value = TextBox2.Text;
        cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = TextBox3.Text;

        cmd = new SqlCommand("submitrecords5", con);
        cmd.CommandType = CommandType.StoredProcedure;
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close(); 
    }
}
Posted
Updated 3-Apr-12 20:31pm
v2
Comments
Mohamed Mitwalli 4-Apr-12 4:01am    
would you clarify more.

Hi,
you can use AddWithValue to add parameters to a SqlCommand along with a value.
for example cmd .Parameters.AddWithValue("@Password", TextBox3.Text);

and here is a useful link with an example:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx[^]

Cheers
 
Share this answer
 
Comments
Reza Ahmadi 4-Apr-12 3:30am    
What was the reason for that vote?
Hello friend.

Need more clarification where u want to pass parameter.

if u r using SQLHelper then pass parameter like

C#
SqlParameter[] SqlPara = new SqlParameter[1];
SqlPara[0] = new SqlParameter("@prmDistrictID", SqlDbType.Int);
SqlPara[0].Value = DistrictID;
SQLHelper.FillDropDown(DDLlist, "TalukaName", "TalukaID", "Pr_ddlTaluka_Select", SqlPara);
               return true;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900