任何人都告诉我如何在此代码中传递参数 [英] how to pass parameters in this code any one tell me

查看:74
本文介绍了任何人都告诉我如何在此代码中传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码........


this is my code........


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(); 
    }
}

推荐答案


您可以使用AddWithValue将参数和值一起添加到SqlCommand.
例如cmd .Parameters.AddWithValue("@ Password",TextBox3.Text);

这是一个带有示例的有用链接:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx [ ^ ]

欢呼
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


你好朋友.

您需要在哪里传递参数的更多说明.

如果您使用SQLHelper,则传递类似
的参数
Hello friend.

Need more clarification where u want to pass parameter.

if u r using SQLHelper then pass parameter like

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;


这篇关于任何人都告诉我如何在此代码中传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆