0

I have a database created in SQL Server 2014 and I've linke it with a project written in C# in Visual Studio. I created a ComboBox in which I get the names of all the tables from my database and a get button which shows the content of the current table when I click on it.

My question is, how can I acces the current columns one by one? Because I want to create Insert, Delete, Update buttons, and I need the name of the columns from the current table for that...

1 Answers1

0
using(var reader = command.ExecuteReader())
{

  reader.Read();

  var table = reader.GetSchemaTable();
  foreach (DataColumn column in table.Columns)
  {
    Console.WriteLine(column.ColumnName);
  }
}
Rahul Sharma
  • 453
  • 3
  • 10
  • It says: "The name command does not exist in the current context" – francydarkcool - Jul 22 '15 at 09:43
  • create an objet of sqlcommand command= new Sqlcommand(param1,param2) and use it . or you can take reference from here :https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand(v=vs.110).aspx – Rahul Sharma Jul 22 '15 at 09:46