0

我在编译代码时出错。它说数据集不能转换为字符串..请帮助我..我已经使用 SQL 存储过程完成了这个..我必须获取保存在主表中的员工姓名来检索 ID,然后 ID 应该检索休假详细信息从休假详细信息表中。

 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
4

2 回答 2

1

您正在设置EmployeeID,如下所示:

EmployeeID = TESTING.GetEmpID(ddlEmpName.Text)

GetEmpID方法返回一个DataSet对象。因此,EmployeeID引用 a DataSet,而不是等于单个 ID 值。稍后,您尝试传递EmployeeID给这样的EmpLeaveDetails方法:

ds1 = TESTING.EmpLeaveDetails(EmployeeID)

但是,该EmpLeaveDetails方法将 aString作为参数。因此,您试图将 a 传递给DataSet需要 a 的方法String。由于DataSet对象无法自动转换为String类型,因此编译器会报错。

要修复它,您需要GetEmpID返回一个字符串,否则您需要DataSet在将其传递给EmpLeaveDetails方法之前从 中检索单个字符串值。

于 2013-03-08T01:57:30.037 回答
1

线

EmployeeID = TESTING.GetEmpID(ddlEmpName.Text)

对我来说似乎是个问题。

你应该使用:

Dim dst As Dataset = TESTING.GetEmpID(ddlEmpName.Text)
EmployeeID = CStr(dst.Tables(0).Rows(0).Item("EmployeeID"))
于 2013-03-08T01:56:18.790 回答