简体   繁体   English

如何在C#中重新排列表中的列

[英]How to rearrange columns in a table in C#

I have created a table "simple gate pass table". 我创建了一个表“简单门通过表”。

I added some columns: ID, Serial, Date, To, Description, Authorized By. 我添加了一些列:ID,序列号,日期,到,描述,授权人。

afterwards, I created this table and later I realized I needed to add 1 more column "From" 之后,我创建了此表,后来我意识到我需要再添加1列“发件人”

but now it won't let me Re-edit existing columns and neither it lets me arrange columns. 但现在它不让我重新编辑现有列,也不允许我排列列。

在此处输入图片说明

This is MSSQL-related question and it has nothing to do with C#. 这是与MSSQL相关的问题,与C#无关。


IIRC MSSQL does not allow you to neither rearrange column order nor add column after/before any other. IIRC MSSQL不允许您重新排列列顺序,也不允许在任何其他之前/之后添加列。 You can only drop column or add one (at the end of the table). 您只能删除列或添加一列(在表末尾)。 If you want to select/display data in some specific order use a SELECT clause with appropriate order, eg: 如果要按某些特定顺序选择/显示数据,请使用具有适当顺序的SELECT子句,例如:

SELECT id, serial, date, from, to, description, authorized_by ...

By the way, from or date are not the very best choices for column names as they are reserved words in most SQL dialects. 顺便说一句, fromdate不列名的最好的选择,因为它们在大多数SQL方言保留字。

you can change order of columns in management studio as follows: 您可以按以下方式更改Management Studio中的列顺序:

  1. Right click on table name in object explorer and select Design. 在对象资源管理器中右键单击表名称,然后选择“设计”。 List of columns will open. 列列表将打开。
  2. In the newly opened list of columns, left click and drag column name to the position you want. 在新打开的列列表中,单击鼠标左键并将其拖到所需的位置。
  3. Press ctrl+s to save. 按ctrl + s保存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM