2013-06-20 27 views
0

我希望我有另一個人在那裏的簡單問題。 即時通訊工作在一個網站,我有一個用戶發佈信息到服務器和張貼後,他們被帶到驗證頁面,告訴他們,如果它成功存儲在.mbd表或不。對於單個表,我沒有這樣做的問題,但是當我想要驗證存儲在多個表上的信息時,我似乎遇到了一個問題。驗證,如果記錄帖子到多個表

該處是即時通訊使用該代碼是工作張貼到單個表

protected void Page_Load(object sender, EventArgs e) 
{ 
    txtVerifiedInfo.Text = Session["txtUserFirstName"].ToString() + 
    "\n" + Session["txtUserLastName"].ToString() + 
    "\n" + Session["txtUserName"].ToString() + 
    "\n" + Session["txtUserPassword"].ToString() + 

;

// Check if the record is successfully saved in the tblUserLogin Table and prints the appropriate message in the text box txtVerifiedInfo 
    if (clsDataLayer.SavePersonnel(Server.MapPath("App_Data\\WSC_DB.mdb"), 
    Session["txtUserFirstName"].ToString(), 
    Session["txtUserLastName"].ToString(), 
    Session["txtUserName"].ToString(), 
    Session["txtUserPassword"].ToString(), 

             )) 
    { 
     txtVerifiedInfo.Text = txtVerifiedInfo.Text + 
     "\nThe information was successfully saved!"; 

    } 
    else 
    { 
     txtVerifiedInfo.Text = txtVerifiedInfo.Text + 
     "\nThe information was NOT saved."; 
    } 
} 

}

以下是我已經嘗試沒有太大的運氣在所有

if (clsDataLayer.Saveneworder(Server.MapPath("App_Data\\WSC_DB.mdb"), 
    Session["txtfirstName"].ToString(), 
    Session["txtlastName"].ToString(), 
    Session["txtstreetAddress"].ToString(), 
    Session["txtcity"].ToString(), 
    Session["txtzipCode"].ToString())) 


    && if (clsDataLayer.Savenewitem(Server.MapPath("App_Data\\WSC_DB.mdb"), 

    Session["jobType"].ToString() + 
    Session["txtmediaContent"].ToString())) 

    { 
     txtVerifiedInfo.Text = txtVerifiedInfo.Text + 
     "\nThe Order successfully submitted!"; 

    } 
    else 
    { 
     txtVerifiedInfo.Text = txtVerifiedInfo.Text + 
     "\n The order did not save, please return to the previous screen and verify all of yourr data is correct, thank you."; 
    } 
} 

}

我想我不是那接近正確,但希望這樣做球公園。

任何幫助,這將是偉大的。 感謝您的時間

+1

表達式'if(condition)&& if(condition2)'沒有意義。它應該是'if(condition && condition2)'。我不是100%肯定這是唯一的問題,雖然.. –

+0

謝謝 - 我會嘗試移動。如果對每個表有不同的會話並嘗試在同一個if語句下列出所有的會話,那麼對於我來說這是不合理的部分。 –

回答

0

爲了簡化,這大約是你現在擁有的一切:

var path = Server.MapPath("App_Data\\WSC_DB.mdb"); 
if (clsDataLayer.Saveorder(path, [order parameters] 
    && clsDataLayer.Saveitem(path, [item parameters]) 
{ 
    txtVerifiedInfo.Text = txtVerifiedInfo.Text + 
    "\nThe Order successfully submitted!"; 
} 
else 
{ 
    txtVerifiedInfo.Text = txtVerifiedInfo.Text + 
    "\n The order did not save, please return to the previous screen and verify all of yourr data is correct, thank you."; 
} 

你給出的代碼是沒有得到很好的結構,在存在於Server.MapPath和不必要的呼叫調用可能更適合作爲數據層類構造函數參數的一部分。

您可能不知道的是&&是一個快捷操作符 - 如果第一部分失敗,則不會調用第二部分參數。這是你想要的行爲嗎?

我懷疑你希望SaveorderSaveitem成功或失敗在一起,作爲一個事務的一部分。既然如此,你可能會更好的在你的數據層類中寫一個新的方法,就是那樣做的。

我假設您的文件名中的.mdb表示您正在使用MS Access?我不確定它是否處理事務以及SQL服務器(例如),因此如果無法保存它的項目(或任何您需要的失敗行爲),您可能需要編寫自己的代碼以刪除該命令。