How to correct this ASP.NET error

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x