工作在數據庫:的ExecuteNonQuery不循環
Alter Procedure Update_MaterialTransactionsto2ForWithdrawal
@materialName varchar(50),
@staffNumber varchar(10),
@description varchar(50),
@transactionID int
As
Begin
Update Table_MaterialTransactions
set Status=2
where StaffNumber = @staffNumber
and CrossSection = @description
and SubSubCategory = @materialName
and Status = 1
and TransactionID = @transactionID
End
在數據訪問層:
public static void UpdateMaterial(string staffNumber,string materialName,string description,int transaction)
{
SqlConnection connection = new SqlConnection(ConnectDatabase.ReturnConnectionString());
//I am passing connection string as the parameter
try
{
connection.Open();
SqlCommand cmd = new SqlCommand("Update_MaterialTransactionsto2ForWithdrawal", connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Clear();
cmd.Parameters.Add("@materialName", SqlDbType.Varchar, 50).Value = materialName;
cmd.Parameters.Add("@staffNumber", SqlDbType.Varchar, 50).Value = staffNumber;
cmd.Parameters.Add("@description", SqlDbType.Varchar, 50).Value = description;
cmd.Parameters.Add("@transactionID", SqlDbTypeInt).Value = transactionID;
int i = cmd.ExecuteNonQuery();
connection.Close();
}
catch(Exception ex)
{
connection.Close();
}
在客戶端:
void btnSubmit_Click(Object sender,EventArgs e)
{
int j=0,k=0;
for(int i=0;i<transactions.Count;i++)
{
string id = "ctl00$ContentPlaceHolder1$" + i.ToString();
CheckBox chk=(CheckBox)Page.FindControl(id);
if(chk.Checked == true)
{
Objects.UpdateMaterial(staffNumbers[i].ToString(), materials[i].ToString(), descriptions[i].ToString(), Convert.ToInt32(transactions[i]));
j++;
}
else
{
Objects.DeleteTheSelectedRowOfMaterialTransaction(staffNumbers[i].ToString(), materials[i].ToString(), descriptions[i].ToString(), Convert.ToInt32(transactions[i]));
k++;
}
}
我有複選框的表當用戶選中複選框並單擊提交時,選中的框將更新數據庫。
但cmd.ExecuteNonQuery()
未執行,它返回0行。它沒有拋出任何錯誤。但是,如果我在數據庫中手動執行此操作,存儲過程工作正常。
請告訴我我哪裏出錯了。
哪裏是烏爾staffNumbeer和othwer變量是declaired – 2013-04-10 10:34:07
我沒有張貼整個代碼... Thje staffNumbers烏爾其在客戶端代碼看到的是一個ArrayList ..我檢查了調試,..正確的參數正在傳遞給Web應用程序的查詢。但是執行查詢返回0行受到影響。它不會拋出任何錯誤。 – codewarrior 2013-04-10 11:16:47
你有一個數字大小爲50,同時添加參數,並在數據庫中有10的大小... – 2013-04-10 11:35:32