저장 프로 시저를 실행하려고하는데 어떤 이유로 계속해서 "Specified cast is not valid"
을 말합니다. "hidSelectedExpenseIDs
"은 id의 자바 스크립트 배열로 채워진 숨겨진 필드입니다.Convert.ToInt32 (value)를 시도 할 때 지정된 캐스트가 유효하지 않습니다.
예 : "hidSelectedExpenseIDs.Value"
은 "123,124,125,126"처럼 보입니다. 따라서 나는 왜 .Split(',')
을 가지고있다.
여기 내 코드입니다 :
public void hasExhistingExpenseInvoice()
{
string[] Expenses = hidSelectedExpenseIDs.Value.Split(',');
//check if there is an existing invoice. Then report back to the user so the
//user knows if he/she has to check overwrite option.
bool invoiceExists = false;
foreach (var expense in Expenses)
{
var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["OSCIDConnectionString"].ToString());
var command = new SqlCommand("p_CaseFiles_Expenses_InvoiceExhists", connection);
command.Parameters.Add(new SqlParameter("@ExpenseID", SqlDbType.Int));
command.Parameters["@ExpenseID"].Value = Convert.ToInt32(expense);
command.CommandType = CommandType.StoredProcedure;
try
{
connection.Open();
invoiceExists = (bool)command.ExecuteScalar();
if (invoiceExists)
{
//previous invoice exhists
Warning1.Visible = true;
Warning1.Text = "There is an exhisting Invoice.";
}
}
catch (SqlException sql)
{
lblStatus.Text = "Couldn't connect to the Database - Error";
lblStatus.ForeColor = System.Drawing.Color.Red;
}
catch (Exception ex)//catches exception here
{
lblStatus.Text = "An error occured";
lblStatus.ForeColor = System.Drawing.Color.Red;
}
finally
{
if (connection.State == ConnectionState.Open)
connection.Close();
}
}
}
이 내 저장 프로 시저입니다 :
ALTER PROCEDURE dbo.[InvoiceExhists]
@ExpenseID int
AS
BEGIN
SELECT InvNumber FROM dbo.Expenses from ExpID = @ExpenseID
END
'hidSelectedExpenseIDs'와 (과) 같은 소리가 항상 포함 된 소리를 포함하지는 않습니다. 이것이 실패 할 때 그 가치는 무엇입니까? – JohnnyHK
중단 점을 사용하여 디버그하고 가변 비용으로 얻는 값을 확인하십시오. – Karthik
'hidSelectedExpenseIDs.Value'에 끝에', '가 없습니까? – manman