コード例 #1
0
        public void show()
        {
            SqlConnection con   = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString);
            string        query = "select Id,  ModuleCode, ModuleName, CourseName from tblModule";

            con.Open();
            SqlCommand cmd = new SqlCommand(query, con);

            cmd.ExecuteNonQuery();
            DataTable      dt  = new DataTable();
            SqlDataAdapter sda = new SqlDataAdapter(cmd);

            sda.Fill(dt);
            GvModule.DataSource = dt;
            GvModule.DataBind();
            con.Close();
        }
コード例 #2
0
        /// <summary>
        /// use ExecuteNonQuery method for displaying the module table data in gridview
        /// </summary>
        public void show()
        {
            // Creating instance of SqlConnection
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnectionString"].ConnectionString);
            //selection query string
            string query = "select Id,  ModuleCode, ModuleName, CourseName from tblModule"; //selection query for table module

            con.Open();                                                                     //opening the connection
            SqlCommand cmd = new SqlCommand(query, con);                                    //Instantiate a new command with a query and connection

            cmd.ExecuteNonQuery();                                                          //Call ExecuteNonQuery to send command
            DataTable      dt  = new DataTable();                                           //creating the new datatable
            SqlDataAdapter sda = new SqlDataAdapter(cmd);

            sda.Fill(dt); //fill the datatable
            GvModule.DataSource = dt;
            GvModule.DataBind();
            con.Close(); //closing the database connection
        }