开发者

how to add all table name of my database in combo box

开发者 https://www.devze.com 2023-01-12 09:04 出处:网络
private void Form1_Load(object sender, EventArgs e) { conn = new SqlConnection(@\"Data Source=ASHISH-PC\\SQLEXPRESS; initial catalog=ashish; integrated security=true\");
private void Form1_Load(object sender, EventArgs e)
{
  conn = new SqlConnection(@"Data Source=ASHISH-PC\SQLEXPRESS; initial catalog=ashish; integrated security=true");
  show();
  foreach (DataT开发者_JAVA百科able dt in ds.Tables)
  {
    comboBox1.Items.Add(dt.TableName[0]);
  }
}


http://msdn.microsoft.com/en-us/library/ms254934(VS.80).aspx

This will give you information on the GetSchema() method which does what you want.

Also googling for GetSchema will get plenty of results which should show you how to get the tables in a database.


there is a library called SMO i havent used but i guess you can do this using SMO. It does not depend on your DataTable directly retrieving table names from sql server. I changed the link below the newer is better http://msdn.microsoft.com/en-us/library/ms162185.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号