Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string        connectionString = DBconnectionDemo.LocalLconStr();
            SqlConnection cn  = new SqlConnection(connectionString);
            SqlCommand    cmd = new SqlCommand("Select * from Course");

            cmd.CommandType = CommandType.Text;
            cmd.Connection  = cn;
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmd);

            //
            cn.Open();
            DataSet dataSet = new DataSet("myDataSetTableName");

            sqlDataAdapter.Fill(dataSet);
            cmd.Dispose();
            sqlDataAdapter.Dispose();
            cn.Close();

            this.GridView2.DataSource = dataSet;
            this.GridView2.DataBind();


            this.ShowResult.Text = dataSet.GetXml();
        }
Exemplo n.º 2
0
        public static void connectionBuildingDemo()
        {
            string connectionString = DBconnectionDemo.LocalLconStr();



            SqlConnection cn  = new SqlConnection(connectionString);
            SqlCommand    cmd = new SqlCommand("Select * from course where credits = 3");

            cmd.CommandType = CommandType.Text;
            cmd.Connection  = cn;
            DataSet        dataSet        = new DataSet( );
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmd);


            cn.Open();

            sqlDataAdapter.Fill(dataSet);
            cmd.Dispose();
            sqlDataAdapter.Dispose();
            cn.Close();
        }
Exemplo n.º 3
0
 protected void Button27_Click(object sender, EventArgs e)
 {
     DBconnectionDemo.connectionBuildingDemo();
     this.TextBox1.Text += "\r\n" + DBconnectionDemo.messageDBconnectionDemo();
 }