foreach (TableRow tableRow in aspTable.Rows) { yourDataTable.Rows.Add(tableRow.Cell[0].Text, tableRow.Cell[1].Text,tableRow.Cell[2].Text, ...); }
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 ShowData_Click(object sender, EventArgs e) { string connetionString = null; SqlConnection connection ; SqlCommand command ; SqlDataAdapter adapter = new SqlDataAdapter(); DataSet ds = new DataSet(); int i = 0; string Sql = null; connetionString = Your Connection string; Sql = "SQL Statement"; connection = new SqlConnection(connetionString); try { connection.Open(); command = new SqlCommand(Sql, connection); adapter.SelectCommand = command; adapter.Fill(ds, "First Table"); adapter.Dispose(); command.Dispose(); connection.Close(); //retrieve data for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++) { MessageBox.Show(ds.Tables[0].Rows[i].ItemArray[0] + " -- " + ds.Tables[0].Rows[i].ItemArray[1]); } } catch (Exception ex) { MessageBox.Show("Can not open connection ! "); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)