国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數(shù)據(jù)庫 > Access > 正文

續(xù)(這個(gè)例子是針對(duì)ACCESS的更新、刪除、還有定位的,希望能對(duì)你有所幫助)

2024-09-07 19:04:55
字體:
供稿:網(wǎng)友
            // btn_help
            //
            this.btn_help.forecolor = system.drawing.systemcolors.activecaptiontext;
            this.btn_help.location = new system.drawing.point(360, 280);
            this.btn_help.name = "btn_help";
            this.btn_help.size = new system.drawing.size(88, 24);
            this.btn_help.tabindex = 3;
            this.btn_help.text = "幫 助(&h)";
            this.btn_help.click += new system.eventhandler(this.btn_help_click);
            //
            // label5
            //
            this.label5.backcolor = system.drawing.color.olive;
            this.label5.borderstyle = system.windows.forms.borderstyle.fixedsingle;
            this.label5.forecolor = system.drawing.systemcolors.activecaptiontext;
            this.label5.location = new system.drawing.point(48, 192);
            this.label5.name = "label5";
            this.label5.size = new system.drawing.size(152, 24);
            this.label5.tabindex = 1;
            this.label5.text = "市場(chǎng)價(jià)格:";
            this.label5.textalign = system.drawing.contentalignment.middlecenter;
            //
            // txt_bookstock
            //
            this.txt_bookstock.borderstyle = system.windows.forms.borderstyle.fixedsingle;
            this.txt_bookstock.location = new system.drawing.point(232, 240);
            this.txt_bookstock.name = "txt_bookstock";
            this.txt_bookstock.size = new system.drawing.size(216, 21);
            this.txt_bookstock.tabindex = 2;
            this.txt_bookstock.text = "";
            //
            // dataedit
            //
            this.autoscalebasesize = new system.drawing.size(6, 14);
            this.autoscroll = true;
            this.backcolor = system.drawing.color.olive;
            this.clientsize = new system.drawing.size(536, 389);
            this.controls.addrange(new system.windows.forms.control[] {
                                                                          this.statusbar,
                                                                          this.btn_help,
                                                                          this.txt_bookid,
                                                                          this.label2,
                                                                          this.label1,
                                                                          this.label3,
                                                                          this.label4,
                                                                          this.label5,
                                                                          this.label6,
                                                                          this.txt_bookname,
                                                                          this.txt_authorname,
                                                                          this.txt_bookprice,
                                                                          this.txt_bookstock,
                                                                          this.btn_delete,
                                                                          this.btn_update,
                                                                          this.btn_movenext,
                                                                          this.btn_movefirst,
                                                                          this.btn_moveprevious,
                                                                          this.btn_movelast});
            this.name = "dataedit";
            this.startposition = system.windows.forms.formstartposition.centerscreen;
            this.text = "dataedit";
            this.windowstate = system.windows.forms.formwindowstate.maximized;
            this.resumelayout(false);

        }
        #endregion

        private void moveprevious()
        {
            if (mybind.position == 0)
            {
                statusbar.text = "數(shù)據(jù)已經(jīng)到頭";
            }
            else
            {
                mybind.position -= 1;
                statusbar.text = "當(dāng)前位置:" +mybind.position.tostring();
            }
        }

        private void movefirst()
        {
            mybind.position = 0;
            statusbar.text = "當(dāng)前位置:" +mybind.position.tostring();
        }

        private void movenext()
        {
            if (mybind.position == mybind.count-1)
            {
                statusbar.text = "數(shù)據(jù)已經(jīng)到尾";
            }
            else
            {
                mybind.position += 1;
                statusbar.text = "當(dāng)前位置:" +mybind.position.tostring();
            }
        }

        private void movelast()
        {
            mybind.position = mybind.count-1;
            statusbar.text = "當(dāng)前位置:" +mybind.position.tostring();
        }

        private void btn_movefirst_click(object sender, system.eventargs e)
        {
            movefirst();
        }

        private void btn_moveprevious_click(object sender, system.eventargs e)
        {
            moveprevious();
        }

        private void btn_movenext_click(object sender, system.eventargs e)
        {
            movenext();
        }

        private void btn_movelast_click(object sender, system.eventargs e)
        {
            movelast();
        }

        private void btn_help_click(object sender, system.eventargs e)
        {
            messagebox.show("數(shù)據(jù)庫操作練習(xí)——定位、更新、刪除",system.datetime.now.toshortdatestring());
        }

        private void btn_delete_click(object sender, system.eventargs e)
        {
            try
            {
                string strconn = "provider=microsoft.jet.oledb.4.0;data source=book.mdb";
                oledbconnection conn = new oledbconnection(strconn);
                
                conn.open();
                string strdelete = "select * from bookstock";
                oledbdataadapter adapter = new oledbdataadapter(strdelete,conn);

                mydataset.tables["bookstock"].rows[mybind.position].delete();
                adapter.update(mydataset,"bookstock");

                statusbar.text = "記錄已經(jīng)刪除";
                conn.close();
            }
            catch(exception ed)
            {
                statusbar.text = "發(fā)生錯(cuò)誤,原因:" + ed.message;
                messagebox.show(ed.tostring());
            }
        }

        private void btn_update_click(object sender, system.eventargs e)
        {
            try
            {
                string strconn = "provider=microsoft.jet.oledb.4.0;data source=book.mdb";
                oledbconnection conn = new oledbconnection(strconn);

                conn.open();

                string strupdt = "update bookstock set booktitle = '"
                    + txt_bookname.text + "',bookauthor = '"
                    + txt_authorname.text + "',bookprice = "
                    + txt_bookprice.text +",bookstock = "
                    + txt_bookstock.text +" where bookid = " + txt_bookid.text;
                oledbcommand comm = new oledbcommand(strupdt,conn);
                comm.executenonquery();

                statusbar.text = "更新成功!";
                conn.close();

                mydataset = null;
                mybind = null;

                if(isbound)
                {
                    txt_bookid.databindings.clear();
                    txt_bookname.databindings.clear();
                    txt_authorname.databindings.clear();
                    txt_bookprice.databindings.clear();
                    txt_bookstock.databindings.clear();
                    isbound = false;
                }

                getconnected();
            }
            catch(exception eu)
            {
                statusbar.text = "發(fā)生錯(cuò)誤,原因:" + eu.message;
            }
        }
    }
}
發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 文成县| 遂溪县| 印江| 巩义市| 麻栗坡县| 德州市| 江阴市| 泸水县| 宿迁市| 图们市| 封丘县| 伊川县| 夏津县| 紫阳县| 平乡县| 西林县| 阳泉市| 华池县| 蒙阴县| 波密县| 安塞县| 大余县| 江津市| 海宁市| 高州市| 叙永县| 临颍县| 阿荣旗| 茶陵县| 瑞安市| 临洮县| 右玉县| 桃园县| 定兴县| 云龙县| 诸暨市| 南川市| 阳新县| 崇州市| 根河市| 克什克腾旗|