如何更正此ASP.NET错误
发布时间:2020-12-16 00:06:52 所属栏目:asp.Net 来源:网络整理
导读:我在我的网页上设计.我的代码如下. using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls;
我在我的网页上设计.我的代码如下.
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; namespace photoshops { public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender,EventArgs e) { } protected void Button1_Click(object sender,EventArgs e) { SqlDataAdapter da = new SqlDataAdapter(); SqlConnection cnn = new SqlConnection(); DataSet ds = new DataSet(); string constr = null; SqlCommand cmd = new SqlCommand(); if (IsValid != null) { constr = @"Data Source=DEVISQLEXPRESS; Initial Catalog =librarymanagement; Integrated Security=SSPI"; cnn.ConnectionString = constr; try { if (cnn.State != ConnectionState.Open) cnn.Open(); } catch (Exception ex) { string str1 = null; str1 = ex.ToString(); } cmd.Connection = cnn; cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "photoset"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@BillNo",TextBox1.Text); cmd.Parameters.AddWithValue("@CustomerName",TextBox2.Text); cmd.Parameters.AddWithValue("@Address",TextBox3.Text); cmd.Parameters.AddWithValue("@StartDate",Rdbsdate.SelectedDate ); cmd.Parameters.AddWithValue("@EndDate",Rdbddate.SelectedDate ); SqlParameter param0 = new SqlParameter("@Systemurl",SqlDbType.VarChar,50); cmd.Parameters.AddWithValue("@Numberofcopies",TextBox7.Text); cmd.Parameters.AddWithValue("@Amount",TextBox8.Text); cmd.Parameters.AddWithValue("@Total",TextBox9.Text); da.SelectCommand = cmd; try { da.Fill(ds); } catch (Exception ex) { string strErrMsg = ex.Message; //throw new applicationException("!!!! An error an occured while //inserting record."+ex.Message) } finally { da.Dispose(); cmd.Dispose(); cnn.Close(); cnn.Dispose(); } if (ds.Tables[0].Rows.Count > 0) { Msg.Text = "Photo setting sucessfullY"; } else { Msg.Text = "photosetting failled"; } } } } }
我的存储过程, set ANSI_NULLS ON set QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[photoset] ( @BillNo Numeric,@CustomerName varchar(300),@Address nvarchar(300),@StartDate datetime,@EndDate datetime,@Systemurl varchar,@Numberofcopies numeric,@Amount numeric,@Total numeric ) AS BEGIN insert into tblphotosetting ( BillNo,CustomerName,Address,StartDate,EndDate,Systemurl,Numberofcopies,Amount,Total ) values ( @BillNo,@CustomerName,@Address,@StartDate,@EndDate,@Systemurl,@Numberofcopies,@Amount,@Total ) END 解决方法
在IF条件之前添加另一个条件,以检查数据集中是否有任何表.如果存储过程没有返回任何表,这将避免错误.
if(ds.Tables.Count > 0) { if (ds.Tables[0].Rows.Count > 0) { Msg.Text = "Photo setting sucessfullY"; } else { Msg.Text = "photosetting failled"; } } 编辑 – 看到存储过程后,只有一个insert语句.除非您编写一些select语句以在存储过程中获得一些结果集,否则您无法用表填充数据集. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 尝试通过方法’HttpConfiguration..ctor(HttpRo
- wcf-data-services – 为什么我的oData响应没有导航属性
- asp.net – Web.config允许特定用户的位置访问
- asp.net-mvc – 当您的视图模型没有域模型那么多字段时,如何
- asp.net-web-api – 在Webapi中使用Url.Link与属性路由2
- asp.net-mvc – 在控制器外部生成路由,类似于Url.RouteUrl(
- asp.net-mvc – DropDown列表onchange事件和MVC中的AJAX
- ASP.net代码背后和来自C#
- asp.net-mvc-4 – 带有返回URL的注销链接(OAuth)
- asp.net – 是否可以强制WebControl呈现为而不是?