.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Interview Question >> ADO.Net >> Post New Question Subscribe to Interview Questions

How to add auto increment column in the DataTable?

Posted By :Syed Shakeer Hussain     Posted Date :July 31, 2009    Points :10   Category :ADO.Net 
To add auto increment column in the DataTable, we can set the AutoIncrement property of the DataColumn object as true and specify the seed value after adding that field into the DataTable object.
// create columns for the DataTable

DataTable dTable = new DataTable();

DataColumn auto = new DataColumn("AutoID", typeof(System.Int32));

dTable.Columns.Add(auto);

// specify it as auto increment field

auto.AutoIncrement = true;

auto.AutoIncrementSeed = 1;

auto.ReadOnly = true;

You can also find related Interview Question to How to add auto increment column in the DataTable?  below: 

How to Rename a COLUMN Name

  
To rename a column ,in a query window execute sp_rename using the following formula:

sp_rename 'TableName.ColumnName', 'NewColumnName', 'COLUMN'


The sp_rename factor and the 'COLUMN' string are required.
The TableName factor is the name of the table that the column belongs to. The ColumnName is the current name of the column. The NewColumnName is the desired name you want to give to the column.

eg:
sp_rename 'Emp.Employeename','Ename','COLUMN'
(More...)

Which property on a Combo Box do you set with a column name, prior to setting the Data Source, to display data in the combo box?

  
ComboBox.DataValueField = "ColumnName"

When we use Databind method for the Combo box we set Display Member and Display Value property to column name. (More...)

How to get the column count of a report?

  
SY-LINSZ system variable gives the column count (line size) and SY-LINCT for line count. (More...)

How you will Hide Column(s) in the Windows Forms DataGridView Control?

  
Set the DataGridViewColumn.Visible property to false.

vb.net:
-------
dataGridView1.Columns("CustomerID").Visible = False

c#.net:
------
dataGridView1.Columns["CustomerID"].Visible = False; (More...)

Is it possible to create Cluster Index on Unique Key Column?

  
Unique key column by default creates a non-cluster index on the column. Primary key creates cluster index on the column. The only difference is Unique key column allows only one null value. So is it possible to have cluster index on Unique key column?

The answer is YES. Though Unique key allows null value but it still maintains the uniqueness of the column. (More...)

How To Update Description Value for a Column in Table using SQL Command?

  
We can Update Description to Column using sp_updateextendedproperty System Store Procedure.
Sample Command to Update Description for Column in a Table:

EXEC sys.sp_updateextendedproperty @name=N'MS_Description', @value=N'My Description for Column Here' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MyTableName', @level2type=N'COLUMN',@level2name=N'ColumnName' (More...)

How To Delete Description Value for a Column in Table using SQL Command?

  
We can Delete Description from Column using sp_dropextendedproperty System Store Procedure.
Sample Command to Delete Description from Column in a Table:

EXEC sys.sp_dropextendedproperty @name=N'MS_Description', @value=N'My Description for Column Here' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MyTableName', @level2type=N'COLUMN',@level2name=N'ColumnName' (More...)

How we can add Description to the Column using Sql Command?

  
We can Add Description to Column using sp_addextendedproperty System Store Procedure.
Sample Command to Insert Description for Column in a Table:

EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'My Description for Column Here' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'MyTableName', @level2type=N'COLUMN',@level2name=N'ColumnName' (More...)

How To Get Description Value for all Column in Table using SQL Command?

  
To Get Description of Columns we need to use system function sys.fn_listextendedproperty.
Command To Get Description Data for all Columns:

SELECT * FROM fn_listextendedproperty(NULL, 'SCHEMA',
'dbo', 'TABLE', 'YourTable Name Here', 'COLUMN', NULL) (More...)

How To Get Description Value for Single Column in Table using SQL Command?

  
To Get Description of Single Column we need to use system function sys.fn_listextendedproperty. we need to pass the column Name is this case.
Command To Get Description Data for Single Columns:

SELECT * FROM fn_listextendedproperty(NULL, 'SCHEMA',
'dbo', 'TABLE', 'Table Name Here', 'COLUMN', 'Column Name Here') (More...)

How to rename a column in SQL?

  
sp_rename 'table_name.Old_Field_Name', 'New_Field_Name' (More...)

Quick Links For Interview Questions Categories:
ASP.Net Windows Application   .NET Framework   C#   VB.Net   ADO.Net  
Sql Server   SharePoint   Silverlight   OOPs   JQuery   JavaScript/VBScript
Biztalk Patten/Practices .IIS WCF WPF WWF
Networking Aptitude Others   All      

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

 
Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.


Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend