求助代码 c#调用.net 存储过程时

来源:百度知道 编辑:UC知道 时间:2024/06/10 23:35:33
cmd.Parameters.AddWithValue("@year","2009");
cmd.Parameters.AddWithValue("@itemno","%IDZ%");

怎么用 textbox的植 替代2009 和 模糊 IDZ
1,2楼答案 都不对, 要注意的是 第2个是 模糊的 到时候 格式怎么写
都不对哦,这个格式的 真难,要不 帮忙远程试吧 我给100分 625427840 谢谢

""+textbox.text.trim()+"" ;
"%"+textbox.text.trim+"%");
当然在数据库中这里可以要加'',
楼主用上面的出现问题的话可以
"'"+textbox.text.trim()+"'" ;
"%'"+textbox.text.trim+"'%");
就是在加上单引号

cmd.Parameters.AddWithValue("@year",textbox1.Text.Trim());
cmd.Parameters.AddWithValue("@itemno","%"+textbox2.Text.Trim()+"%");

直接代便可,都是字符串类型

public bool addProducts(Product c)
{
try
{
SqlConnection con=db.getCon();
SqlCommand cmd=new SqlCommand();
cmd.Connection=con;
cmd.CommandText="addProducts";
cmd.CommandType=CommandType.StoredProcedure;
cmd.Parameters.Add("@productName",SqlDbType.VarChar,50);
cmd.Parameters.Add("@typeId",SqlDbType.Int,4);
cmd.Parameters.Add("@number",SqlDbType.VarChar,50);