1

Hello Every one I m stuck in one problem but I don't how to resolve it

I have dataTable InvoiceViewWithUserDataTable related to view : InvoiceWithUserView (database)

I want to add 2 columns in run time to datatable InvoiceViewWithUserDataTable

InvoiceViewWithUserDataTable .Columns.Add("IntegrationSuccessed", GetType(Integer))
 InvoiceViewWithUserDataTable .Columns.Add("ResponseGet", GetType(String))

InvoiceViewWithUserDataTable.FillMyData(startindex, lineNumber)

Foreach(var row  in InvoiceViewWithUserDataTable)
{
    row.ResponseGet (error)
    row.IntegrationSuccessed (error)

}

but the in results I can't get the value for this 2 column even if my stored pro return them

sam it
  • 54
  • 7

1 Answers1

1

Try this---

InvoiceViewWithUserDataTable.Columns.Add("NewColumn", typeof(System.Int32));

foreach(DataRow row in InvoiceViewWithUserDataTable .Rows)
{
//need to set value to NewColumn column
row["NewColumn"] = 0; // or set it to some other value
}

Also, you are populating the data from the database then it clear the existing data or create a new data table object. First, get the data from the database then add a new column and after that insert values in these columns.
Also, refer the following link for run time column
Add new column and data to datatable that already contains data - c#

Shyam Sa
  • 331
  • 4
  • 8
  • thank you for the answer but I get my data from the database i don t want to fill them with default value my store pro return the value but i don t know who i can assign them – sam it Jun 19 '19 at 11:09
  • Stored procedure returns the dataset (assuming you are using ADO.net) and the dataset is the collection of the data table. You can find the values from that table. No need to create a new data table. Link to get value in dataset https://stackoverflow.com/questions/12973773/stored-procedure-return-into-dataset-in-c-sharp-net DataTable firstTable = dataSet.Tables[0]; https://learn.microsoft.com/en-us/dotnet/api/system.data.dataview.totable?redirectedfrom=MSDN&view=netframework-4.8#System_Data_DataView_ToTable – Shyam Sa Jun 19 '19 at 11:14
  • thank you again , the problem my database is related to the view witch does not contain the 2 columns , I created one store pro return all column of the view and 2 two colums my orginal view was (join between user and invoice) but now i add new join with table integration , wich return two column more (IntegrationSuccessed, ResponseGet) – sam it Jun 19 '19 at 11:25
  • the join is in my store pro i didn't change the view – sam it Jun 19 '19 at 11:26
  • did you create the data table manually with each column of as per the new SP? – Shyam Sa Jun 19 '19 at 13:29