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 閱讀(197) 評論(0)  編輯  收藏 所屬分類: DotNet

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


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 太仆寺旗| 平谷区| 溆浦县| 沂水县| 内丘县| 三明市| 榕江县| 电白县| 平顺县| 鹤岗市| 昌吉市| 双柏县| 兴国县| 德安县| 连山| 霍邱县| 游戏| 当涂县| 高雄市| 灵璧县| 阿勒泰市| 许昌县| 潞西市| 鸡西市| 南召县| 普安县| 邮箱| 家居| 武邑县| 石嘴山市| 石楼县| 容城县| 日喀则市| 绥德县| 永仁县| 天峨县| 吴江市| 弥勒县| 广水市| 黎川县| 都安|