Store all columns name of Sql table in one string in VB.NET

In this article we are going to explain How to get all columns name of Sql table in one string in vb.net.
  • 2889
How to get all columns name of  Sql table in one string in vb.net 
if you want to retrive all column's name of any sql table, you can try this code:


Dim
 dsColumnName As New DataSet 
Dim Con As New SqlClient.SqlConnection(ConnectionString) 
Con.Open() 
Dim strSql As String = "SELECT column_name FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = '" & TableName & "'" 
Dim dAdapter As New SqlClient.SqlDataAdapter(strSql, Con) 
dAdapter.Fill(dsColumnName) 
Dim ColumnsName_String As String = "" 
For i As Integer = 0 To dsColumnName.Tables(0).Rows.Count - 1 
ColumnsName_String = ColumnsName_String & 
"," & dsColumnName.Tables(0).Rows(i).Item(0) 
Next 
If ColumnsName_String.StartsWith(","Then 
ColumnsName_String = ColumnsName_String.Remove(0, 1) 
End If 
Return ColumnsName_String

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.