如何纠正这种错误ASP.NET [英] How to correct this ASP.NET error

查看:80
本文介绍了如何纠正这种错误ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计我的网页。我的code是如下。

 使用系统;
  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
      {
          保护无效的Page_Load(对象发件人,EventArgs的发送)
          {          }          保护无效的button1_Click(对象发件人,EventArgs的发送)
          {
              SqlDataAdapter的大=新的SqlDataAdapter();
              SqlConnection的CNN =新的SqlConnection();
              DataSet的DS =新的DataSet();
              字符串构造= NULL;
              CMD的SqlCommand =新的SqlCommand();
              如果(IsValid的!= NULL)
              {
                  构造= @数据源= DEVI \\ SQLEX $ P $干燥综合征;初始目录= librarymanagement;
                     集成安全性= SSPI;
                  cnn.ConnectionString =构造;
                  尝试
                  {
                      如果(cnn.State!= ConnectionState.Open)
                          cnn.Open();
                  }
                  赶上(异常前)
                  {
                      字符串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(@客户名称,TextBox2.Text);
                  cmd.Parameters.AddWithValue(@地址,TextBox3.Text);
                  cmd.Parameters.AddWithValue(@起始日期,Rdbsdate.SelectedDate);
                  cmd.Parameters.AddWithValue(@结束日期,Rdbddate.SelectedDate);
                  SqlParameter的参数0 =新的SqlParameter(@ Systemurl,SqlDbType.VarChar,50);
                  cmd.Parameters.AddWithValue(@ Numberofcopies,TextBox7.Text);
                  cmd.Parameters.AddWithValue(@金额,TextBox8.Text);
                  cmd.Parameters.AddWithValue(@共,TextBox9.Text);
                  da.SelectCommand = CMD;
                  尝试
                  {
                      da.Fill(DS);
                  }
                  赶上(异常前)
                  {
                      字符串strErrMsg = ex.Message;
                      //抛出新ApplicationException的(!!!!一个错误而发生
                      //插入记录。+ ex.Message)
                  }
                  最后
                  {
                      da.Dispose();
                      cmd.Dispose();
                      cnn.Close();
                      cnn.Dispose();
                  }
                  如果(ds.Tables [0] .Rows.Count大于0)
                  {
                      Msg.Text =照片设置成功地;
                  }
                  其他
                  {
                      Msg.Text =照相failled
                  }
              }
          }
      }
  }


  

我的错误
             图像不插入如何在我的code修改请给我code
             如何纠正。


我的存储过程,

 设置ANSI_NULLS ON
设置QUOTED_IDENTIFIER ON
 走ALTER PROCEDURE [DBO]。[photoset]

    @BillNo数字,
    @CustomerName的varchar(300),
    @address nvarchar的(300),
    @StartDate日期时间,
    @EndDate日期时间,
    @Systemurl VARCHAR,
    @Numberofcopies数字,
    @Amount数字,
    @Total数字
)如
开始
    插入tblphotosetting
    (
      BillNo,
      顾客姓名,
      地址,
      开始日期,
      结束日期,
      Systemurl,
      复印数量,
      量,
      总
    )
    值
    (
      @BillNo,
      @顾客姓名,
      @地址,
      @开始日期,
       @结束日期,
      @Systemurl,
      @复印数量,
      @量,
      @总
    )
结束


解决方案

添加其他条件IF condtion前检查,如果你在你的数据集的任何表。这将避免错误如果存储过程没有返回任何表。

 如果(ds.Tables.Count大于0)
{
   如果(ds.Tables [0] .Rows.Count大于0)
   {
      Msg.Text =照片设置成功地;
   }
   其他
   {
      Msg.Text =照相failled
   }
}

修改 -

看到您的存储过程后,只有一个INSERT语句。有没有办法,你将能够使用表格来填补你的数据集,除非你写的一些select语句得到一些结果在存储过程中设置的。

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=DEVI\SQLEXPRESS; 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆