来自'对象'的隐式转换到vb 2008中的' String

时间:2014-04-24 16:26:53

标签: vb.net

错误显示 - 来自'对象'的隐式转换to' String'。

Imports System.Data.OleDb

Public Class Main
Dim inc As Integer = 0
Dim MaxRows As Integer

Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As New OleDb.OleDbDataAdapter
Dim sql As String

Private Sub Main_Load(ByVal sender As System.Object, 
    ByVal e As System.EventArgs) Handles MyBase.Load  
    con.ConnectionString 
     = "Provider=Microsoft.ACE.OLEDB.12.0;DataSource=C:\Users\dell\Desktop\todolist.accdb"

    con.Open()

    sql = "SELECT * from task"
    da = New OleDb.OleDbDataAdapter(sql, con)
    da.Fill(ds, "todolist")

    con.Close()

    MaxRows = ds.Tables("todolist").Rows.Count

    lblTaskName.Text = ds.Tables("task").Rows(inc).Item(1)
    lblPriority.Text = ds.Tables("task").Rows(inc).Item(2)
    lblCreateDate.Text = ds.Tables("task").Rows(inc).Item(3)
    dtpDueDate.Text = ds.Tables("task").Rows(inc).Item(4)

End Sub

1 个答案:

答案 0 :(得分:1)

该错误消息告诉您,您的代码正在尝试将对象分配给采用字符串的变量或参数。所有对象都可以转换为字符串,就像Hans在评论中所说的那样。但分析这项任务是否真的是你的意图是明智的,而不是盲目地转换类型。汉斯在这里为你做了分析,但请记住,他下次可能不在那里。