This Is A FineDay

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            93 隨筆 :: 0 文章 :: 69 評論 :: 0 Trackbacks

          ?

          using?System;
          using?System.Data;
          using?System.Configuration;
          using?System.Collections;
          using?System.Web;
          using?System.Web.Security;
          using?System.Web.UI;
          using?System.Web.UI.WebControls;
          using?System.Web.UI.WebControls.WebParts;
          using?System.Web.UI.HtmlControls;
          using?MySql.Data.MySqlClient;

          public ?partial? class ?news?:?System.Web.UI.Page
          {
          ?
          ????
          protected ? void ?Page_Load(object?sender,?EventArgs?e)
          ????
          {

          ?????????DataTable????dt?
          = ? new ?DataTable();
          ????????string?connStr?
          = ?String.Format( " server={0};user?id={1};?password={2};?database=test;?pooling=false " ,
          ????????????????
          " 127.0.0.1 " ,? " root " ,? " 123 " );
          ????????MySqlConnection?conn?
          = ? new ?MySqlConnection(connStr);
          ????????conn.Open();
          ????????MySqlDataAdapter?msda?
          = ? null ;
          ????????MySqlCommandBuilder?cb?
          = ? null ;
          ????????
          try
          ????????
          {
          ????????????
          // 查詢
          ????????????msda? = ? new ?MySqlDataAdapter( " select?*?from?test " ,?conn);
          ????????????cb?
          = ? new ?MySqlCommandBuilder(msda);???
          ????????????msda.Fill(dt);
          ????????}

          ????????
          catch ?(MySqlException?ex)
          ????????
          {
          ????????????System.Console.WriteLine(
          " Failed?to?populate?mysql?data:? " ? + ?ex.Message);
          ????????}

          ????????
          finally
          ????????
          {
          ????????????
          if ?(conn? != ? null )?conn.Close();
          ????????}


          ????????
          // 更新
          ????????conn.Open();
          ????????DataRow?row1?
          = ?dt.Rows[ 0 ];
          ????????row1[
          " name " ]? = ? " 00 " ;
          ????????row1[
          " password " ]? = ? " 00 " ;
          ????????msda.Update(dt);
          ????????dt.AcceptChanges();
          ????????conn.Close();

          ????????
          // 新增
          ????????conn.Open();
          ????????DataRow?row2?
          = ?dt.NewRow();
          ????????row2[
          " id " ]? = ? 6 ;
          ????????row2[
          " name " ]? = ? " 6 " ;
          ????????row2[
          " password " ]? = ? " 6 " ;
          ????????dt.Rows.Add(row2);
          ????????msda.Update(dt);
          ????????dt.AcceptChanges();
          ????????conn.Close();

          ????????
          // 刪除
          ????????conn.Open();
          ????????DataRow?row3?
          = ?dt.Rows[ 1 ];
          ????????row3.Delete();
          ????????msda.Update(dt);
          ????????dt.AcceptChanges();
          ????????conn.Close();
          ????????
          ????????
          // 填充頁面
          ???????? this .DataList1.DataSource? = ?dt.DefaultView;
          ????????
          this .DataList1.DataBind();

          ????}

          ??
          }

          posted on 2008-09-23 23:59 Peter Pan 閱讀(204) 評論(0)  編輯  收藏 所屬分類: DotNet

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 江都市| 大冶市| 天水市| 井陉县| 体育| 荥阳市| 龙胜| 乌兰浩特市| 三亚市| 靖远县| 桐庐县| 连平县| 麻栗坡县| 乌什县| 绍兴市| 嘉定区| 曲阜市| 资溪县| 永丰县| 高陵县| 武义县| 望城县| 武穴市| 盖州市| 凤冈县| 商都县| 迁西县| 勐海县| 平江县| 阜新市| 化德县| 揭西县| 通榆县| 饶平县| 凌源市| 黄山市| 阜阳市| 灵山县| 洱源县| 加查县| 大庆市|