Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to generate one more column in my database table using datatable or other way

like:-

employee id int
employee name varchar(50)
employee address varchar(50)

i want to generate automatic one more column (employee salary) using datatable without
enter database
Posted

1 solution

The fastest way to do this is to change your query. For example

SQL
SELECT EmployeeID,
       EmployeeName,
       EmployeeAddress,
       0 as EmployeeSalary
FROM Employee


Doing this will automatically populate the new Column EmployeeSalary with a value of 0 which you can manipulate at run time.

If you dont want to change SQL then you can also do like this

DataColumn salaryCol = DataTable.Columns.Add("EmployeeSalary", typeof(Int32));
salaryCol.AllowDBNull = false;
 
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