我設計了我的網頁,但是我得到下面的錯誤。如何清除錯誤?如何在調用存儲過程時清除錯誤?
我的代碼
protected void btnSave_Click(object sender, EventArgs e)
{
Int32 st;
int len = browseFilepath.PostedFile.ContentLength;
byte[] pic = new byte[len];
browseFilepath.PostedFile.InputStream.Read(pic, 0, len);
SqlCommand Cmd = new SqlCommand();
SqlConnection Cnn = new SqlConnection();
string ConnectionString;
ConnectionString = ConfigurationManager.ConnectionStrings["PhotostudioConnectionString"].ConnectionString;
Cnn.ConnectionString = ConnectionString;
if (Cnn.State != ConnectionState.Open)
Cnn.Open();
Cmd.Connection = Cnn;
Cmd.CommandType = CommandType.StoredProcedure;
Cmd.CommandText = "sproc_Ins_PhotoSettingsDetails";
Cmd.Parameters.Clear();
// Cmd.Parameters.AddWithValue("@Id", txtBillNo.Text);
Cmd.Parameters.AddWithValue("@Name", txtCName.Text);
Cmd.Parameters.AddWithValue("@Phoneno", txtPhone.Text);
Cmd.Parameters.AddWithValue("@Startdate", rdStartDate.SelectedDate);
Cmd.Parameters.AddWithValue("@Enddate", rdEndDate.SelectedDate);
Cmd.Parameters.Add("@Systemurl", SqlDbType.Image).Value = pic;
SqlParameter Src = new SqlParameter("@FilePath", SqlDbType.NVarChar, 450);
Src.Value = browseFilepath.PostedFile.FileName;
Cmd.Parameters.Add(Src);
Cmd.Parameters.AddWithValue("@Size", cmbSize.SelectedItem.Text );
Cmd.Parameters.AddWithValue("@Amount",txtAmt.Text);
Cmd.Parameters.AddWithValue("@Extracopies", txtNoofcopies.Text);
Cmd.Parameters.AddWithValue("@Examount",TextBox1.Text);
Cmd.Parameters.AddWithValue("@Lamination", Ddl.SelectedItem.Text );
Cmd.Parameters.AddWithValue("@Laamount", txtlami.Text);
Cmd.Parameters.AddWithValue("@Total", txtTot.Text);
Cmd.Parameters.AddWithValue("@Grandtotal", txtgrandtot.Text);
Cmd.Parameters.AddWithValue("@Paidamount", txtPaid.Text);
Cmd.Parameters.AddWithValue("@Balance", txtbalance.Text);
try
{
st = Convert.ToInt32(Cmd.ExecuteScalar());
}
catch (Exception ex)
{
throw new ApplicationException(
"!!! An Error Occured While getting Data From Hdr_AccountType." + ex.Message);
lblError.Visible = true;
lblError.Text = "!!! An Error Occured While " + ex.Message.ToString();
return;
}
Cmd.Dispose();
錯誤
而從Hdr_AccountType獲取數據時出錯。將數據類型nvarchar轉換爲數字時出錯。
我的存儲過程:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[sproc_Ins_PhotoSettingsDetails]
(
[email protected] as Numeric(18,0),
@Name as Varchar(100),
@Phoneno as Numeric(18,0),
@Startdate as DateTime,
@Enddate as DateTime,
@Systemurl as Image,
@FilePath as NVarchar(450),
@Size as nvarchar(50),
@Amount as numeric(18,0),
@Extracopies as numeric(18,0),
@Examount as numeric (18,0),
@Lamination as numeric(18,0),
@Laamount as numeric(18,0),
@Total as numeric(18,0),
@Grandtotal as numeric (18,0),
@Paidamount as Numeric(18,0),
@Balance as numeric (18,0)
)
AS
BEGIN
INSERT INTO tblPhotosettingsMaster (Name, Phoneno, Startdate, Enddate,
Systemurl, FilePath, Size, Amount,
Extracopies, Examount, Lamination, Laamount,
Total, Grandtotal, Paidamount, Balance)
VALUES (@Name, @Phoneno, @Startdate, @Enddate,
@Systemurl, @FilePath, @Size, @Amount,
@Extracopies, @Examount, @Lamination, @Laamount,
@Total, @Grandtotal, @Paidamount, @Balance)
SELECT @@Identity
END
註釋try/catch並查看拋出的異常。 – iandayman 2011-06-11 05:52:28