Filling data at a particular location in a Data Table in C#

后端 未结 3 1957
故里飘歌
故里飘歌 2021-01-15 22:30

I am working with C# and Asp.Net. Is it possible to fill a particular location of a Data table.

I have a Data Table dt, and is contains this this k

相关标签:
3条回答
  • 2021-01-15 23:13

    You can address individual cells with:

    dt.Rows[rowIndex][columnIndex]
    

    The column can be addressed by name as well:

    dt.Rows[rowIndex]["customer2"]
    

    Mind that the output is of type Object, so you might need to cast it to the appropriate data type if you want to read its value.

    0 讨论(0)
  • 2021-01-15 23:24

    You can actually do this:

    1. Filter your table to the target row
    2. In the target row, write to the desired column

    Code example:

    Dim vRows() As DataRow
    vRows = dt.Select("DATA='Shop1'")
    vRows(0)("customer2") = "YourDataHere"
    

    This way you create an array of rows which is a reference to the DataTable, so you can directly edit the array.

    If you write this table to a database, don't forget to set up a DataAdapter and use the .Update method.

    0 讨论(0)
  • 2021-01-15 23:33

    Yes you must specify index roww and column, suggest you this link http://msdn.microsoft.com/en-us/library/z16c79x4(v=vs.110).aspx

    0 讨论(0)
提交回复
热议问题