当前位置: 代码迷 >> ASP.NET >> asp.net中,调用存储过程?解决办法
  详细解决方案

asp.net中,调用存储过程?解决办法

热度:9947   发布时间:2013-02-26 00:00:00.0
asp.net中,调用存储过程?
string   constr=System.Configuration.ConfigurationSettings.AppSettings[ "connection "];
SqlConnection   con=new   SqlConnection(constr);
con.Open();

SqlCommand   cmd=new   SqlCommand();
cmd.CommandText= "p_GetUnitsInCustomerDetail ";
cmd.CommandType=System.Data.CommandType.StoredProcedure;

                        SqlDataAdapter   sa=new   SqlDataAdapter( "p_GetUnitsInCustomerDetail ",con);
SqlParameter   pa=new   SqlParameter( "@U_Customer ",System.Data.SqlDbType.VarChar,20);
pa.Value=this.TextBox1.Text;
sa.SelectCommand.Parameters.Add(pa);
DataSet   ds=new   DataSet();
//cmd.Parameters.Add( "@U_Customer ",System.Data.SqlDbType.VarChar,20);
sa.Fill(ds);
this.DataGrid1.DataSource=ds.Tables[0].DefaultView;
this.DataGrid1.DataBind();
  上面是我在asp.net中调用sql2000的一个存储过程,为什么执行后,老提示说:第   1   行:   'p_GetUnitsInCustomerDetail '   附近有语法错误。
这是为什么啊?请大家帮我看看啊~~~

------解决方案--------------------------------------------------------
没有指定commandType
------解决方案--------------------------------------------------------
错了,指定了,好像没有用那个command
------解决方案--------------------------------------------------------
p_GetUnitsInCustomerDetail里边是一条SQL语句吧?语句有错
------解决方案--------------------------------------------------------
SqlDataAdapter sa = new SqlDataAdapter(cmd);
------解决方案--------------------------------------------------------
没使用command
SqlDataAdapter sa=new SqlDataAdapter(cmd,con);
  相关解决方案