2011-06-11 3 views
0

내 웹 페이지를 디자인했지만 아래 오류가 나타납니다. 오류를 해결하는 방법? Hdr_AccountType에서 데이터를 가져 오는 동안저장 프로 시저를 호출 할 때 오류를 지우는 방법?

내 코드

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(); 

오류가

오류가 발생했습니다. 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 
+0

try/catch를 주석 처리하고 어떤 예외가 발생하는지 확인하십시오. – iandayman

답변

3

으로 보내는 데이터가 저장 프로 시저가 텍스트 (.Text = nvarchar)로 보내지지만 SP가 숫자 입력 매개 변수를 사용한다고 가정합니다. 대부분의 경우 SQL은 숫자 문자열을 자체적으로 숫자로 변환하지만 txtgrandtot.Text는 실제로 "$ 123.23"이라고 가정 해 보겠습니다. 그러면이 오류가 발생합니다. 예외는 C# 코드에서 발생하지 않으며 SQL Server에서 발생시킵니다.

0

당신이 디버그 시도 :

var ret = Cmd.ExecuteScalar(); 

저장 반환 값을 제어 할 수? 번호인가?

내가 Haukman에 동의

업데이트! 숫자가되어야하는 문자 값을 찾는 입력 매개 변수를 확인하십시오!

+0

초보자입니다. 변경하는 방법을 편집하십시오. – Malliga

관련 문제