System.Data.Datarow C# error

后端 未结 6 669
傲寒
傲寒 2021-01-19 04:06

So I\'m in the verge of creating my first C# system. I use my vb.net system to use as my reference.

This is the code on my vb.net system:

Dim value A         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-19 04:42

    The line should read

    int value = double.Parse(dt.Rows[0]["TransID"].ToString());
    

    dt.Rows[0] returns the first row, dt.Rows[0]["TransID"] returns the value of the "TransID" column as object from the first row. As Parse only takes strings, not objects, you need ToString() as well.

    To avoid ToString you could also use the following, which is even better:

    int value = (int)Convert.ToDouble(dt.Rows[0]["TransID"]);
    

提交回复
热议问题