Print -
Find Tables in a Dataset - Sql Server
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string connetionString = null;
SqlConnection connection;
SqlCommand command ;
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
string sql = null;
connetionString = "Data Source=ServerName;Initial Catalog=DatabaseName;User ID=UserName;Password=Password";
sql = "Your SQL Statement Here";
connection = new SqlConnection(connetionString);
try
{
connection.Open();
command = new SqlCommand(sql, connection);
adapter.SelectCommand = command;
adapter.Fill(ds, "SQL Temp Table");
adapter.Dispose();
command.Dispose();
connection.Close();
foreach (DataTable tables in ds.Tables)
{
MessageBox.Show (tables.TableName);
}
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! ");
}
}
}
}