指定:
SelectCommand1.CommandType = CommandType.StoredProcedure;
SelectCommand1.CommandType = CommandType.StoredProcedure;
解决方案 »
- 查出来的数据怎么在后台取出来调用呢?
- 各位大侠,msdn的在线发送信息是怎么做的
- asp.net 中什么时候在HTML里写代码?
- 问大家一个控件绑定事件的问题??(解决给分!!)
- asp.net基于角色的权限验证时,可否不要cookie而用session???
- 框架集间传值的问题 急急急急!!!! 在线等!!!!
- 这问题谁能解决?
- datagrid中编辑列中点更新的时候怎么弹出一个确认框
- 请问各位高手能否使DataGrid或DataList显示固定的行数
- 有谁见过这个极端的古怪问题?
- 怎样使用datagrid的超链接列新开一个小窗口,并且要传参数,在线等待
- Win2000 server 下如何配置ASP.net?
{
int ListID;
ListID = 0; SqlConnection connFaq = new SqlConnection(this.connection);
SqlCommand cmdAddList = new SqlCommand("faq_list_insert",connFaq);
cmdAddList.CommandType = CommandType.StoredProcedure;
SqlParameter prmListType = new SqlParameter("@ListType", SqlDbType.TinyInt,0);
prmListType.Direction = ParameterDirection.Input;
cmdAddList.Parameters.Add(prmListType);
prmListType.Value = ListType;
SqlParameter prmRefID = new SqlParameter("@RefID", SqlDbType.NVarChar, 50);
prmRefID.Direction = ParameterDirection.Input;
cmdAddList.Parameters.Add(prmRefID);
prmRefID.Value = RefID; SqlParameter prmUserID = new SqlParameter("@UserID", SqlDbType.NVarChar, 20);
prmUserID.Direction = ParameterDirection.Input;
cmdAddList.Parameters.Add(prmUserID);
prmUserID.Value = UserID;
SqlParameter prmListID = new SqlParameter("@ListID", SqlDbType.Int,0);
prmListID.Direction = ParameterDirection.Output;
cmdAddList.Parameters.Add(prmListID);
prmListID.Value = ListID;
connFaq.Open(); cmdAddList.ExecuteNonQuery(); connFaq.Close(); return (int)prmListID.Value;
}
{
public dealbudget()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public string ReturnValue;
public void GetResult(string StockCode,string ExCode,string BsFlag, decimal NewPrice)
{
//=========================调用pr_budget存储过程===========================
String strConn;
SqlConnection cn;
strConn = ConfigurationSettings.AppSettings["stock"];
// 连接到stock数据库
cn = new SqlConnection(strConn);
SqlCommand cm = new SqlCommand("",cn);
cn.Open();
cm.CommandText="pr_budget";
cm.CommandType =CommandType.StoredProcedure;
cm.Parameters.Add(new SqlParameter("@p_userid",SqlDbType.Int,20)); //用户id
cm.Parameters.Add(new SqlParameter("@p_stockcode",SqlDbType.VarChar,6)); //股票代码
cm.Parameters.Add(new SqlParameter("@p_excode",SqlDbType.VarChar,6)); //证交所代码
cm.Parameters.Add(new SqlParameter("@p_bsflag",SqlDbType.VarChar,6)); //买卖标志
cm.Parameters.Add(new SqlParameter("@p_newprice",SqlDbType.Decimal)); //最新价
cm.Parameters.Add(new SqlParameter("@p_freecp",SqlDbType.Decimal,14,ParameterDirection.Output,false,0,0,string.Empty, DataRowVersion.Default, null)); //可用资金
cm.Parameters.Add(new SqlParameter("@p_canbuy",SqlDbType.Decimal,14,ParameterDirection.Output,false,0,0,string.Empty, DataRowVersion.Default, null)); //可买股票数
cm.Parameters.Add(new SqlParameter("@p_cansell",SqlDbType.Decimal,14,ParameterDirection.Output,false,0,0,string.Empty, DataRowVersion.Default, null)); //可卖股票数
cm.Parameters.Add(new SqlParameter("@p_win",SqlDbType.Decimal,14,ParameterDirection.Output,false,0,0,string.Empty, DataRowVersion.Default, null)); //保本价
cm.Parameters.Add(new SqlParameter("@p_error",SqlDbType.VarChar,40,ParameterDirection.Output,false,0,0,string.Empty, DataRowVersion.Default, null)); //错误信息
cm.Parameters.Add(new SqlParameter("returnvalue",SqlDbType.Int,4,ParameterDirection.ReturnValue, false, 0, 0,string.Empty, DataRowVersion.Default, null));
cm.Parameters["@p_userid"].Value=System.Convert.ToInt16(HttpContext.Current.Session["UserId"]);
//cm.Parameters["@p_userid"].Value= 1;
cm.Parameters["@p_stockcode"].Value = StockCode;
cm.Parameters["@p_excode"].Value = ExCode;
cm.Parameters["@p_bsflag"].Value = BsFlag;
cm.Parameters["@p_newprice"].Value = NewPrice;
cm.ExecuteNonQuery();
ReturnValue = cm.Parameters["returnvalue"].Value.ToString();
FreeCp = cm.Parameters["@p_freecp"].Value.ToString();
CanBuy = cm.Parameters["@p_canbuy"].Value.ToString();
CanSell = cm.Parameters["@p_cansell"].Value.ToString();
Win = cm.Parameters["@p_win"].Value.ToString();
ErrorInfo = cm.Parameters["@p_error"].Value.ToString(); //========================================================================
} public string ErrorInfo;
public string FreeCp;
public string CanBuy;
public string CanSell;
public string Win; }
(1)、不带输入、输出参数的简单的存储过程调用。
存储过程内容:
CREATE PROCEDURE pro AS
select * from 报表清单调用方法:
private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection myConnection = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=南糖;Data Source=DOT_NET_SERVER");
myConnection.Open();
SqlDataAdapter myCommand = new SqlDataAdapter("pro", myConnection); //pro是存储过程名
//设置命令对象类型为存储过程
myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet();
myCommand.Fill(ds, "报表清单");
DataGrid1.DataSource=ds.Tables["报表清单"].DefaultView;
DataGrid1.DataBind();
}(2)、带输入参数的存储过程的调用
存储过程内容:
CREATE PROCEDURE pro_inputpara @bbid varchar(10) AS
select 报表编号,报表名称 from 报表清单 where 报表编号=@bbid调用方法:
private void Page_Load(object sender, System.EventArgs e)
{
SqlConnection myConnection = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;User ID=sa;Initial Catalog=南糖;Data Source=DOT_NET_SERVER");
myConnection.Open();
SqlDataAdapter myCommand = new SqlDataAdapter("pro_inputpara", myConnection);
myCommand.SelectCommand.CommandType = CommandType.StoredProcedure;myCommand.SelectCommand.Parameters.Add(new SqlParameter("@bbid", SqlDbType.NVarChar, 15));
myCommand.SelectCommand.Parameters["@bbid"].Value = "sb0001";//传递参数
DataSet ds = new DataSet();
myCommand.Fill(ds, "报表清单");
DataTable dt = ds.Tables["报表清单"];
this.DataGrid1.DataSource = dt.DefaultView;
this.DataGrid1.DataBind();
}
@Firstname varchar,
@LastName varchar,
@Id int OUTPUT
As SELECT @ID = UserID
FORM tblUsers
WHERE FirstName =@FirstName
AND LastName = @LastName