如何更正此 ASP.NET 错误 [英] How to correct this ASP.NET error
问题描述
我正在我的网页中进行设计.我的代码如下.
使用系统;使用 System.Collections;使用 System.Configuration;使用 System.Data;使用 System.Linq;使用 System.Web;使用 System.Web.Security;使用 System.Web.UI;使用 System.Web.UI.HtmlControls;使用 System.Web.UI.WebControls;使用 System.Web.UI.WebControls.WebParts;使用 System.Xml.Linq;使用 System.Data.SqlClient;命名空间photoshops{公共部分类 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();数据集 ds = 新数据集();字符串constr = null;SqlCommand cmd = 新的 SqlCommand();如果 (IsValid != null){constr = @"Data Source=DEVISQLEXPRESS; 初始目录 =librarymanagement;综合安全=SSPI";cnn.ConnectionString = constr;尝试{if (cnn.State != ConnectionState.Open)cnn.Open();}捕获(异常前){字符串 str1 = 空;str1 = ex.ToString();}cmd.Connection = cnn;cmd.CommandType = CommandType.StoredProcedure;cmd.CommandText = "照片集";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;尝试{da.Fill(ds);}捕获(异常前){字符串 strErrMsg = ex.Message;//throw new applicationException("!!!! 发生错误//插入记录."+ex.Message)}最后{da.Dispose();cmd.Dispose();cnn.关闭();cnn.Dispose();}如果(ds.Tables[0].Rows.Count > 0){Msg.Text = "图片设置成功";}别的{Msg.Text = "图片设置失败";}}}}}
<块引用>
我的错误图像未插入如何更改我的代码 请向我发送代码如何纠正.
我的存储过程,
设置 ANSI_NULLS ON设置 QUOTED_IDENTIFIER ON去更改程序 [dbo].[photoset](@BillNo 数字,@CustomerName varchar(300),@地址 nvarchar(300),@StartDate 日期时间,@EndDate 日期时间,@Systemurl varchar,@Numberofcopies 数字,@Amount 数字,@总数字)作为开始插入到 tblphotosetting(比尔不,顾客姓名,地址,开始日期,结束日期,系统网址,复印数量,数量,全部的)价值观(@比尔不,@顾客姓名,@地址,@开始日期,@结束日期,@系统网址,@复印数量,@数量,@全部的)结尾
在 IF 条件之前添加另一个条件以检查您的数据集中是否有任何表.如果存储过程没有返回任何表,这将避免错误.
if(ds.Tables.Count > 0){如果(ds.Tables[0].Rows.Count > 0){Msg.Text = "图片设置成功";}别的{Msg.Text = "图片设置失败";}}
编辑 -
看到你的存储过程后,只有一个insert语句.除非您编写一些选择语句以在存储过程中获取一些结果集,否则您无法用表格填充数据集.
I'm designing in my webpage. My code is a follows.
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";
}
}
}
}
}
MY ERROR image are not insert how to change in my code pls send me code How to rectify.
My stored procedure,
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
Add another condition before the IF condtion to check if you have any tables in your dataset. This will avoid the error if the stored procedure is not returning any tables.
if(ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
Msg.Text = "Photo setting sucessfullY";
}
else
{
Msg.Text = "photosetting failled";
}
}
EDIT -
After seeing your stored procedure, there is only a insert statement. There is no way you will be able to fill your dataset with tables unless you write some select statement to get some result set in your stored proc.
这篇关于如何更正此 ASP.NET 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!