问题描述
PrivateSubButton1_Click(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)HandlesButton1.ClickDimmyconnAsNewSqlConnection("server=(local);"&_"database=jdglsys;integratedsecurity=sspi")DimsqldaAsSqlDataAdapter=NewSqlDataAdapter("checkoutdate",myconn)sqlda.SelectCommand.CommandType=CommandType.StoredProcedureDimbeginningdateAsSqlParameter=sqlda.SelectCommand.Parameters.Add("beginningdate",SqlDbType.DateTime)beginningdate.Direction=ParameterDirection.Input'设置输入参数的开始时间beginningdate.Value=DateTimePicker1.ValueDimendingdateAsSqlParameter=sqlda.SelectCommand.Parameters.Add("@endingdate",SqlDbType.DateTime)endingdate.Direction=ParameterDirection.Input'设置输入参数的截至时间endingdate.Value=DateTimePicker2.ValueDimnumcustomersoutAsSqlParameter=sqlda.SelectCommand.Parameters.Add("@numcustomersout",SqlDbType.Int)'设置参数为输出参数numcustomersout.Direction=ParameterDirection.OutputDimreturnvalueAsSqlParameter=sqlda.SelectCommand.Parameters.Add("returnvalue",SqlDbType.Int)'设置参数为存储过程的返回值returnvalue.Direction=ParameterDirection.ReturnValueDimdsAsDataSet=NewDataSetTrymyconn.Open()sqlda.Fill(ds,"入住单")myconn.Close()DataGrid1.SetDataBinding(ds,"入住单")Ifds.Tables("入住单").Rows.Count=0ThenMessageBox.Show("找不到符合指定期间的离店客户记录,请重试!!!","抱歉",MessageBoxButtons.OK,MessageBoxIcon.Question)EndIfCatchexAsExceptionMessageBox.Show(ex.ToString,"请注意",MessageBoxButtons.OK,MessageBoxIcon.Question)EndTryEndSubEndClass下面是我的存储过程代码createproceduredbo.checkoutdate@beginingdatedatetime='01/01/2007',@EndingDatedatetime='01/01/2010',@numCustomersOUTintegeroutputasselect客人姓名,性别,客房编号as客房号,客房类型,房价,预付押金,入住类型,预付方式,折扣,客人来源,人数,身份证号,地址,退房时间,联系电话,备注from入住单set@numCustomersOUT=@@rowcountreturn1go运行时报错说beginingdate不是checkoutdate的参数
解决方案
解决方案二:
DimbeginningdateAsSqlParameter=sqlda.SelectCommand.Parameters.Add("@beginningdate",SqlDbType.DateTime)