2013-03-08 55 views
0

我在編譯代碼時出錯。它說該數據集不能轉換爲字符串..請幫助我..我已經通過使用SQL存儲過程做到了這一點..我必須獲取保存在主表中的員工姓名以檢索ID,然後ID應檢索離開的詳細信息從請假細節表。將數據集轉換爲VB中的字符串

Public Shared Function GetEmpID(ByVal EmpName As String) As DataSet 
    Dim db As Database = DatabaseFactory.CreateDatabase(HttpContext.Current.Session("CompanyID").ToString) ' TO Get Database Connection 
    Dim dbCommand As DbCommand = db.GetStoredProcCommand("spRetrieveEmpID") ' Stored Procedure to Execute 
    db.AddInParameter(dbCommand, "EmployeeName", DbType.String, EmpName) ' Parameter for Stored Procedure 
    Return db.ExecuteDataSet(dbCommand) ' Execute Stored Procedure 
End Function 

Public Shared Function EmpLeaveDetails(ByVal EmployeeID As String) As DataSet 
    Dim db As Database = DatabaseFactory.CreateDatabase(HttpContext.Current.Session("CompanyID").ToString) ' TO Get Database Connection 
    Dim dbCommand As DbCommand = db.GetStoredProcCommand("spHRLeaveEntitlement") ' Stored Procedure to Execute 
    db.AddInParameter(dbCommand, "EmployeeID", DbType.String, EmployeeID) ' Parameter for Stored Procedure 
    Return db.ExecuteDataSet(dbCommand) ' Execute Stored Procedure 
End Function 

這是我leave.aspx.vb碼

Private Sub ddlEmpName_SelectedIndexChanged(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles ddlEmpName.SelectedIndexChanged 

    EmployeeID = TESTING.GetEmpID(ddlEmpName.Text) 

    If ds.Tables(0).Rows.Count > 0 Then 
     dgLeaveDetails.DataSource = ds 
     dgLeaveDetails.DataBind() 
    End If 

    ds1 = TESTING.EmpLeaveDetails(EmployeeID) 
    dgLeaveDetails.DataSource = ds1 

    ddlEmpName.SelectedIndex = -1 
    dgLeaveDetails.Rebind() 

End Sub 
+0

你能包括de錯誤信息嗎? – emecas 2013-03-08 01:51:12

+0

@emecas:謝謝你的倡議..錯誤已經解決.. :) – user1617943 2013-03-08 03:02:24

回答

1

EmployeeID = TESTING.GetEmpID(ddlEmpName.Text) 

貌似這個問題給我。

你應該使用:

Dim dst As Dataset = TESTING.GetEmpID(ddlEmpName.Text) 
EmployeeID = CStr(dst.Tables(0).Rows(0).Item("EmployeeID")) 
+0

非常感謝你..它工作.. :) – user1617943 2013-03-08 02:59:23

1

要設置EmployeeID,像這樣:

EmployeeID = TESTING.GetEmpID(ddlEmpName.Text) 

GetEmpID方法返回一個DataSet對象。因此,EmployeeID引用了DataSet,而不是等於單個ID值。以後,您嘗試通過EmployeeIDEmpLeaveDetails方法是這樣的:

ds1 = TESTING.EmpLeaveDetails(EmployeeID) 

然而,EmpLeaveDetails方法採用String作爲參數。因此,您正在嘗試將DataSet傳遞給期望String的方法。由於DataSet對象不能自動轉換爲String類型,因此編譯器會提供該錯誤。

要解決該問題,您需要讓GetEmpID返回一個字符串,否則在將其傳遞給EmpLeaveDetails方法之前,您需要從DataSet中檢索單個字符串值。

+0

感謝您的幫助:) – user1617943 2013-03-08 03:01:21

相關問題