简体   繁体   English

从字符串“”到类型整数的转换无效

[英]Conversion From String “ ” to Type Integer is not valid

I know this has been ask already I tried everything but none work for me. 我知道这已经是一个问题,我已经尝试了所有方法,但对我没有任何帮助。 Please help this is my first post.. 请帮助这是我的第一篇文章。

My Code ` 我的代码

    Dim MyDataRow As DataRow = MyDataTbl.Rows(0)
    Dim strName As String
    Dim strState As String

    strName = MyDataRow("ContactName")
    strState = MyDataRow("State")
    NameTxt.Text = strName.ToString
    StateTxt.Text = strState.ToString

    If MyDataTbl.Rows.Count = 0 Then
        NameTxt.Text = " "
        StateTxt.Text = " "
        Exit Sub
    End If


    NameTxt.Text = MyDataTbl.Rows("ContactName").ToString() "ERROR HERE"
    StateTxt.Text = MyDataTbl.Rows("State").ToString()

The error is Conversion from String "Contact Name" to type 'Integer' is not valid . 错误是Conversion from String "Contact Name" to type 'Integer' is not valid

Retrieving from The DataTable seems wrong in your code. DataTable检索似乎在您的代码中是错误的。

Use NameTxt.Text = MyDataTbl.Rows(<Row Number>).Item("<Column Name>") To retrieve the Data from DataTable . 使用NameTxt.Text = MyDataTbl.Rows(<Row Number>).Item("<Column Name>")DataTable检索DataTable

Data Table might contains more than one row so while retrieving the data, it is important to specify the Row Number. 数据表可能包含多个行,因此在检索数据时,指定行号很重要。 After specifying the Row number, we must choose the Column from which we want to retrieve the Data and that is done by .Item(<Column Number as Integer or Column Name as string>) method. 指定行号之后,我们必须选择要从中检索数据的列,这是通过.Item(<Column Number as Integer or Column Name as string>)方法完成的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM