Click here to Skip to main content
15,895,423 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can any one help me.

I want to create a datatable one time and add data through button_click event
Posted
Comments
VishwaKL 18-Dec-15 3:34am    
Please elaborate more on your concerns, describe the problem.

Or Specify what you have tried

1 solution

I am not sure what is your overall requirement since it would be helpful to give you a better solution. However I will just give you what you asked.

Define a datatable.
C#
DataTable dtable = new DataTable();
dtable.Clear();
dtable.Columns.Add("Name");
dtable.Columns.Add("Id");


Now, add rows to it in your button click function.
C#
DataRow myRow= dtable.NewRow();
myRow["Name"] = "Bob";
myRow["Id"] = "231";
dtable.Rows.Add(myRow);


I hope it helps you achieve your goal. Please get back if you need any more help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900