且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

帮助在“搜索"按钮中创建存储过程

更新时间:2023-02-07 11:29:20

尝试使用第三行.
Try using the third line.
string productid = pid.Text;
            string productname = pn.Text;
            SqlConnection conn = new SqlConnection("Data Source=FAROOQPC\\SQLEXPRESS; Database=db_first; Integrated Security=SSPI");
            command.CommandType = CommandType.StoredProcedure;
            command.Parameters.Add("@ProductID", SqlDbType.VarChar).Value = productid;
            command.Parameters.Add("@ProductName", SqlDbType.VarChar).Value = productname;   
            SqlCommand command = new SqlCommand("GetProducts", conn);            
            SqlDataAdapter adapter = new SqlDataAdapter(command);
            DataSet ds = new DataSet();
            adapter.Fill(ds, "Products");
            DataTable dt = ds.Tables[0];
            foreach (DataRow dr in dt.Rows)
            {
                Password.Text = dr["@ProductName"].ToString();
                //code for remaining text boxes
            }



希望它能起作用.



Hope it will work.


实际上非常容易. SP中的SQL语句调用必须已经包含参数定义:

It''s actually quite easy. The SQL statement callin you SP has to include the parameter definition already:

SqlCommand command = new SqlCommand("GetProducts @ProductID", conn);



SqlCommand就是真正的名字.为sql命令本身不存在的内容提供参数将使您无所适从.

干杯!

-MRB



The SqlCommand is what will be really called. Supplying a parameter for something that is not present in the sql command itself would get you nowhere.

Cheers!

-MRB