데이터베이스에 데이터를 보내는 데 사용하는 다른 클래스의 메서드가 있습니다. 그 방법은 here입니다.ListBox를 반복 할 때 오류 : 지정된 캐스트가 유효하지 않습니다.
public Int32 AddOrder(clsStock NewItem)
{
//this function takes the data passed via NewItem
//and passes it to the parameters for the stored procedure
//
//create an instance of the data dictionary
clsDataDictionary DD = new clsDataDictionary();
//create an instance of the object class
Int32 ReturnValue;
//create an instance of the data conduit
clsDataConduit Items = new clsDataConduit();
//pass the data for this address
Items.AddParameter(DD.sproc_tblOrders_Add_AuthId, NewItem.AuthId);
Items.AddParameter(DD.sproc_tblOrders_Add_ItemId, NewItem.ItemId);
Items.AddParameter(DD.sproc_tblOrders_Add_DateOrdered, NewItem.DateOrdered);
Items.AddParameter(DD.sproc_tblOrders_Add_Cancel, NewItem.Cancel);
//execute the stored procedure
ReturnValue = Items.Execute(DD.sproc_tblOrders_Add);
//return the primary key value
return ReturnValue;
}
난 내 목록 상자를 통해 반복하고 목록 상자에서 각 항목에 대해 그 방법을 실행하는 데 사용하고 내 aspx 페이지에 방법뿐만 아니라 here입니다.
protected void btnSubmit_Click1(object sender, EventArgs e)
{
//create an instance of the collection class
clsStockCollection Items = new clsStockCollection();
foreach(int id in lstAdded.Items)
{
TheItem.AuthId = 5;
TheItem.ItemId = Convert.ToInt32(lstAdded.Items[id].Value);
TheItem.Cancel = "false";
Items.AddOrder(TheItem);
}
Response.Redirect("Order.aspx");
}
내 웹 사이트를 실행하고 다음과 같은 오류주고 년대 btnSubmit에 충돌하는 경우 :
aspx
페이지의 방법에
"Specified cast is not valid"
(2 페이스트 빈 파일)
어떤 생각 이유를 뭐야?
의 더 나은 당신이 코드 블록 :이 응답에 대한 – Habib