Linq using projection operation of the dataset

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ProjectionByLinq
{
    public partial class Frm_Main : Form
    {
        public Frm_Main()
        {
            InitializeComponent();
        }

        void Frm_Main_Load Private (SENDER Object, EventArgs E)
        {
            String the ConnectionString = "Server-GI7E47AND9R WIN = \ the LS; Database = db_TomeTwo; UID = SA; pwd ="; // declare the connection string
            using (SqlConnection Conn = new SqlConnection ( ConnectionString )) // create a database connection object
            {
                String sqlstr = "SELECT * from tb_Bookinfo Top. 5"; // definition of query
                SqlDataAdapter da = new SqlDataAdapter (sqlstr, Conn); // Create a data object bridge
                DataSet ds = new DataSet ( ); // create data objects
                da.Fill (ds, "tb_Bookinfo") ; // fill the dataset
                of 3 lines // query data book information table book title and author
                var result = from b in ds.Tables [ "tb_Bookinfo "].AsEnumerable()
                             select new
                             {
                                 B_name = b.Field <String> ( "b_name"),
                                 b_author = b.Field <String> ( "b_author")
                             };
                the foreach (var in Item Result) Results // iterate outputs
                {
                    RichTextBox1.Text + = " book name: "+ item.b_name +"   **  author: "+ item.b_author +" \ the n-";
                }
            }
        }
    }
}
 

Guess you like

Origin blog.51cto.com/14510327/2434390