如何在我的数据库表中生成一个列 [英] How to Generate one more column in my Database table

查看:116
本文介绍了如何在我的数据库表中生成一个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用数据表或其他方式在我的数据库表中再生成一列



喜欢: -



员工ID int

员工姓名varchar(50)

员工地址varchar(50)



i希望使用datatable自动生成一个列(员工薪水)而不用

输入数据库

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

推荐答案

执行此操作的最快方法是更改您的查询。例如



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

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





这样做会自动填充新的Column EmployeeSalary,其值为0,你可以在运行时操作。



如果您不想更改SQL,那么您也可以这样做





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;


这篇关于如何在我的数据库表中生成一个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆