在asp:Wizard
的第一步,我有一個使用DirectoryServices
進行身份驗證的登錄。但是,我想採取UserID
,Date
和SCOPE_IDENTITY()
並將其插入表中。這是我嘗試過的。當我點擊下一頁時,信息未插入,但AD功能正確檢查。我不知道我做錯了如何在嚮導活動步驟中執行SQL插入?
protected void OnActiveStepChanged(object sender, EventArgs e)
{
//check for the employee in AD
string Domain = "mydomain.local";
string EmployeeID = txtEmpID.Text;
string Password = txtPassword.Text;
string ADStatus = null;
// If the ActiveStep is changing to Step2, check to see whether the
// user authenticated the AD Login Process. If it is, skip to the Step2 step.
if (Wizard1.ActiveStepIndex == Wizard1.WizardSteps.IndexOf(this.WizardStep2))
{
if (AuthenticateActiveDirectory(Domain, EmployeeID, Password) == true)
{
//If success ...
ADStatus = "Success";
Session["SessionADStatus"] = ADStatus;
string strDepartment = ddlDepartment.SelectedValue;
SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["myconnection"].ConnectionString);
SqlCommand cmd1 = new SqlCommand("INSERT INTO [pharm_OrderID](UserID, RequestType, CreateDate) values (@UserID, @RequestType, @CreateDate);", conn1);
cmd1.CommandType = CommandType.Text;
conn1.Open();
string strUserID = txtEmpID.Text;
cmd1.Parameters.Add("@UserID", SqlDbType.NVarChar, 50);
cmd1.Parameters["@UserID"].Value = strUserID;
string strRequestType = ddlReturnType.SelectedValue;
cmd1.Parameters.Add("@ReturnType", SqlDbType.NVarChar, 50);
cmd1.Parameters["@ReturnType"].Value = strRequestType;
string strCreateDate = lblOrderAttemptTime.Text;
cmd1.Parameters.Add("@CreateDate", SqlDbType.NVarChar, 50);
cmd1.Parameters["@CreateDate"].Value = strCreateDate;
conn1.Dispose();
cmd1.Dispose();
Wizard1.ActiveStepIndex = Wizard1.WizardSteps.IndexOf(this.WizardStep2);
}
else
{
ADStatus = "Failure";
Session["SessionADStatus"] = ADStatus;
lblADError.Visible = true;
lblADError.Text = "Unable to authenticate Employee ID or Password.";
Wizard1.ActiveStepIndex = Wizard1.WizardSteps.IndexOf(this.WizardStep1);
}
}
}
首先,從您的UI事件處理程序中獲取數據層代碼。 – paqogomez
@paqogomez爲什麼? – Skullomania
如果您在事件處理程序中擁有該代碼,則無法重用它。 [N層體系結構](http://en.wikipedia.org/wiki/Multitier_architecture)將規定您有一個數據層(一組類),它與數據庫進行交互,處理業務邏輯的業務層和一個用戶界面,這是你的前端。 – paqogomez