




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
.NET編程技術(shù)實驗報告實驗報告(2012-2013學(xué)年第二學(xué)期)課程名稱:.NET編程技術(shù)學(xué)生姓名:蘭天翔專業(yè)班級:10級計算機2班學(xué)院:信電學(xué)院學(xué)號:14514026學(xué)生成績:實驗一Windows應(yīng)用編程[實驗?zāi)康腯掌握windows窗體的基本屬性、事件和方法的使用。掌握常用控件的具體使用。[實驗內(nèi)容]完成字體設(shè)置程序。實驗代碼:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespaceFontSetpublicpartialclassForm1:FormstringfontFamily="宋體";floatfontSize=10.0f;FontStylefontStyle=FontStyle.Regular;publicForm1(){InitializeComponent();}privatevoidsetFont(){this.richTextBox1.Font=newFont(fontFamily,fontSize,fontStyle);}privatevoidrbSongti_CheckedChanged(objectsender,EventArgse)if(rbSongti.Checked)this.fontFamily="宋體";setFont();privatevoidrbLishu_CheckedChanged(objectsender,EventArgse)if(rbLishu.Checked)this.fontFamily="隸書";setFont();privatevoidcbBold_CheckedChanged(objectsender,EventArgse)if(cbBold.Checked){this.fontStyle=this.fontStyle|FontStyle.Bold;}elsethis.fontStyle-=FontStyle.Bold;setFont();privatevoidcbItalic_CheckedChanged(objectsender,EventArgse)if(cbItalic.Checked){this.fontStyle=this.fontStyle|FontStyle.Italic;}else{this.fontStyle-=FontStyle.Italic;}setFont();privatevoidcbUnderline_CheckedChanged(objectsender,EventArgse)if(cbUnderline.Checked){this.fontStyle=this.fontStyle|FontStyle.Underline;}else{this.fontStyle-=FontStyle.Underline;}setFont();privatevoidnumericUpDown1_ValueChanged(objectsender,EventArgse)this.fontSize=Convert.ToSingle(this.numericUpDown1.Value);setFont();ProgramusingSystem;usingSystem.Collections.Generic;usingSystem.Windows.Forms;namespaceFontSetstaticclassProgram///應(yīng)用程序的主入口點。[STAThread]staticvoidMain()Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(newForm1());Forml.DesignernamespaceFontSetpartialclassForm1///必需的設(shè)計器變量。privateSystem.ComponentModel.IContainercomponents=null;///清理所有正在使用的資源。///<paramname="disposing">如果應(yīng)釋放托管資源,為true;否則為false。</param>protectedoverridevoidDispose(booldisposing)if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);#regionWindows窗體設(shè)計器生成的代碼///設(shè)計器支持所需的方法-不要///使用代碼編輯器修改此方法的內(nèi)容。privatevoidInitializeComponent()this.groupBox1=newSystem.Windows.Forms.GroupBox();this.groupBox2=newSystem.Windows.Forms.GroupBox();this.groupBox3=newSystem.Windows.Forms.GroupBox();this.rbSongti=newSystem.Windows.Forms.RadioButton();this.rbLishu=newSystem.Windows.Forms.RadioButton();this.numericUpDown1=newSystem.Windows.Forms.NumericUpDown();this.cbBold=newSystem.Windows.Forms.CheckBox();this.cbItalic=newSystem.Windows.Forms.CheckBox();this.cbUnderline=newSystem.Windows.Forms.CheckBox();this.richTextBox1=newSystem.Windows.Forms.RichTextBox();this.groupBox1.SuspendLayout();this.groupBox2.SuspendLayout();this.groupBox3.SuspendLayout();((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();this.SuspendLayout();//groupBox1this.groupBox1.Controls.Add(this.rbLishu);this.groupBox1.Controls.Add(this.rbSongti);this.groupBox1.Location=newSystem.Drawing.Point(3,206);this.groupBox1.Name="groupBox1";this.groupBox1.Size=newSystem.Drawing.Size(208,199);this.groupBox1.TabIndex=0;this.groupBox1.TabStop=false;this.groupBox1.Text="字體";//groupBox2this.groupBox2.Controls.Add(this.numericUpDown1);this.groupBox2.Location=newSystem.Drawing.Point(217,206);this.groupBox2.Name="groupBox2";this.groupBox2.Size=newSystem.Drawing.Size(201,199);this.groupBox2.TabIndex=0;this.groupBox2.TabStop=false;this.groupBox2.Text="大小";//groupBox3this.groupBox3.Controls.Add(this.cbUnderline);this.groupBox3.Controls.Add(this.cbItalic);this.groupBox3.Controls.Add(this.cbBold);this.groupBox3.Location=newSystem.Drawing.Point(424,206);this.groupBox3.Name="groupBox3";this.groupBox3.Size=newSystem.Drawing.Size(216,199);this.groupBox3.TabIndex=0;this.groupBox3.TabStop=false;this.groupBox3.Text="風(fēng)格";//rbSongtithis.rbSongti.AutoSize=true;this.rbSongti.Location=newSystem.Drawing.Point(27,41);this.rbSongti.Name="rbSongti";this.rbSongti.Size=newSystem.Drawing.Size(47,16);this.rbSongti.TabIndex=0;this.rbSongti.TabStop=true;this.rbSongti.Text="宋體";this.rbSongti.UseVisualStyleBackColor=true;this.rbSongti.CheckedChanged+=newSystem.EventHandler(this.rbSongti_CheckedChanged);//rbLishuthis.rbLishu.AutoSize=true;this.rbLishu.Location=newSystem.Drawing.Point(27,81);this.rbLishu.Name="rbLishu";this.rbLishu.Size=newSystem.Drawing.Size(47,16);this.rbLishu.TabIndex=1;this.rbLishu.TabStop=true;this.rbLishu.Text="隸書";this.rbLishu.UseVisualStyleBackColor=true;this.rbLishu.CheckedChanged+=newSystem.EventHandler(this.rbLishu_CheckedChanged);//numericUpDown1this.numericUpDown1.Location=newSystem.Drawing.Point(36,52);this.numericUpDown1.Name="numericUpDown1";this.numericUpDown1.Size=newSystem.Drawing.Size(120,21);this.numericUpDown1.TabIndex=2;this.numericUpDown1.Value=newdecimal(newint[]{10,0,0,0});this.numericUpDown1.ValueChanged+=newSystem.EventHandler(this.numericUpDown1_ValueChanged);//cbBoldthis.cbBold.AutoSize=true;this.cbBold.Location=newSystem.Drawing.Point(50,41);this.cbBold.Name="cbBold";this.cbBold.Size=newSystem.Drawing.Size(48,16);this.cbBold.TabIndex=3;this.cbBold.Text="粗體";this.cbBold.UseVisualStyleBackColor=true;this.cbBold.CheckedChanged+=newSystem.EventHandler(this.cbBold_CheckedChanged);//cbItalicthis.cbItalic.AutoSize=true;this.cbItalic.Location=newSystem.Drawing.Point(50,81);this.cbItalic.Name="cbItalic";this.cbItalic.Size=newSystem.Drawing.Size(48,16);this.cbItalic.TabIndex=4;this.cbItalic.Text="斜體";this.cbItalic.UseVisualStyleBackColor=true;this.cbItalic.CheckedChanged+=newSystem.EventHandler(this.cbItalic_CheckedChanged);//cbUnderlinethis.cbUnderline.AutoSize=true;this.cbUnderline.Location=newSystem.Drawing.Point(50,121);this.cbUnderline.Name="cbUnderline";this.cbUnderline.Size=newSystem.Drawing.Size(60,16);this.cbUnderline.TabIndex=5;this.cbUnderline.Text="下劃線";this.cbUnderline.UseVisualStyleBackColor=true;this.cbUnderline.CheckedChanged+=newSystem.EventHandler(this.cbUnderline_CheckedChanged);//richTextBox1this.richTextBox1.Location=newSystem.Drawing.Point(0,0);this.richTextBox1.Name="richTextBox1";this.richTextBox1.Size=newSystem.Drawing.Size(640,200);this.richTextBox1.TabIndex=1;this.richTextBox1.Text="";//Form1this.AutoScaleDimensions=newSystem.Drawing.SizeF(6F,12F);this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;this.ClientSize=newSystem.Drawing.Size(641,404);this.Controls.Add(this.richTextBox1);this.Controls.Add(this.groupBox3);this.Controls.Add(this.groupBox2);this.Controls.Add(this.groupBox1);this.Name="Form1";this.Text="Form1";this.groupBox1.ResumeLayout(false);this.groupBox1.PerformLayout();this.groupBox2.ResumeLayout(false);this.groupBox3.ResumeLayout(false);this.groupBox3.PerformLayout();((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();this.ResumeLayout(false);#endregionprivateSystem.Windows.Forms.GroupBoxgroupBox1;privateSystem.Windows.Forms.GroupBoxgroupBox2;privateSystem.Windows.Forms.GroupBoxgroupBox3;privateSystem.Windows.Forms.RadioButtonrbLishu;privateSystem.Windows.Forms.RadioButtonrbSongti;privateSystem.Windows.Forms.NumericUpDownnumericUpDown1;privateSystem.Windows.Forms.CheckBoxcbUnderline;privateSystem.Windows.Forms.CheckBoxcbItalic;privateSystem.Windows.Forms.CheckBoxcbBold;privateSystem.Windows.Forms.RichTextBoxrichTextBox1;實驗二圖形圖像編程[實驗?zāi)康腯掌握Graphics類。掌握基本的繪圖方法。掌握圖像的顯示和處理方法。[實驗內(nèi)容]完成畫板應(yīng)用。在窗體的空白處繪圖,并將圖片保存起來。實驗代碼:usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;namespaceWindrawpublicpartialclassForm1:FormGraphicsdc;Bitmapbmp=newBitmap(800,800);Pointp0;Pointp1;boolisPress=false;publicForm1()InitializeComponent();dc=Graphics.FromImage(bmp);privatevoidbutton1_Click(objectsender,EventArgse)this.saveFileDialog1.Filter="BMP圖片|*.bmp";if(this.saveFileDialog1.ShowDialog()==DialogResult.OK){this.bmp.Save(this.saveFileDialog1.FileName);}privatevoiddrawImage()if(isPress)dc.DrawLine(Pens.Red,p0,p1);this.pictureBox1.Image=bmp;privatevoidpictureBox1_MouseDown(objectsender,MouseEventArgse)p0=e.Location;isPress=true;privatevoidpictureBox1_MouseMove(objectsender,MouseEventArgse)p1=e.Location;drawImage();p0=p1;privatevoidpictureBox1_MouseUp(objectsender,MouseEventArgse)p1=e.Location;drawImage();isPress=false;Program:usingSystem;usingSystem.Collections.Generic;usingSystem.Windows.Forms;namespaceWindrawstaticclassProgram///應(yīng)用程序的主入口點。[STAThread]staticvoidMain()Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(newForm1());Forml.designernamespaceWindrawpartialclassForm1///必需的設(shè)計器變量。privateSystem.ComponentModel.IContainercomponents=null;///清理所有正在使用的資源。///<paramname="disposing">如果應(yīng)釋放托管資源,為true;否則為false。</param>protectedoverridevoidDispose(booldisposing)if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);#regionWindows窗體設(shè)計器生成的代碼///設(shè)計器支持所需的方法-不要///使用代碼編輯器修改此方法的內(nèi)容。privatevoidInitializeComponent()this.pictureBox1=newSystem.Windows.Forms.PictureBox();this.button1=newSystem.Windows.Forms.Button();this.saveFileDialog1=newSystem.Windows.Forms.SaveFileDialog();((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();this.SuspendLayout();//pictureBox1this.pictureBox1.BackColor=System.Drawing.Color.White;this.pictureBox1.Location=newSystem.Drawing.Point(0,0);this.pictureBox1.Name="pictureBox1";this.pictureBox1.Size=newSystem.Drawing.Size(517,361);this.pictureBox1.TabIndex=0;this.pictureBox1.TabStop=false;this.pictureBox1.MouseDown+=newSystem.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseDown);this.pictureBox1.MouseMove+=newSystem.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseMove);this.pictureBox1.MouseUp+=newSystem.Windows.Forms.MouseEventHandler(this.pictureBox1_MouseUp);//button1this.button1.Location=newSystem.Drawing.Point(0,367);this.button1.Name="button1";this.button1.Size=newSystem.Drawing.Size(75,23);this.button1.TabIndex=1;this.button1.Text="保存";this.button1.UseVisualStyleBackColor=true;this.button1.Click+=newSystem.EventHandler(this.button1_Click);//Form1this.AutoScaleDimensions=newSystem.Drawing.SizeF(6F,12F);this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;this.ClientSize=newSystem.Drawing.Size(517,392);this.Controls.Add(this.button1);this.Controls.Add(this.pictureBox1);this.Name="Form1";this.Text="Form1";((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();this.ResumeLayout(false);#endregionprivateSystem.Windows.Forms.PictureBoxpictureBox1;privateSystem.Windows.Forms.Buttonbutton1;privateSystem.Windows.Forms.SaveFileDialogsaveFileDialog1;實驗三數(shù)據(jù)庫編程[實驗?zāi)康腯理解ADO.NET對象模型。熟悉常用數(shù)據(jù)邦定控件的使用方法。[實驗內(nèi)容]完成簡單學(xué)生信息系統(tǒng),能夠查詢學(xué)生信息,增、刪、改學(xué)生信息。實驗代碼:FormlusingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Data.SqlClient;namespaceWinStuDBpublicpartialclassForm1:FormSqlHelperhelper=newSqlHelper();publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsender,EventArgse)DataSetds;//ds=helper.SelectSqlReturnDataSet("select*fromstudent");//stringcmdText="select*fromstudentwheressex=@ssexandsno=@sno";//stringssex;//ssex="男";//stringsno;//sno="1";//SqlParameter[]pars=newSqlParameter[]//newSqlParameter("@ssex",ssex),//newSqlParameter("@sno",sno)//ds=helper.SelectSqlReturnDataSet(cmdText,pars,CommandType.Text);ds=helper.SelectSqlReturnDataSet("select*fromstudent",null,CommandType.Text);this.dataGridView1.DataSource=ds.Tables[0];privatevoiddataGridView1_CellClick(objectsender,DataGridViewCellEventArgse)//this.dataGridView1.CurrentRow.Selected=true;bindData();privatevoidbtAdd_Click(objectsender,EventArgse)stringsql="insertintostudent(sno,sname,ssex)values(@sno,@sname,@ssex)";SqlParameter[]pars=newSqlParameter[]newSqlParameter("@sno",tbSno.Text),newSqlParameter("@sname",tbSname.Text),newSqlParameter("@ssex",tbSsex.Text)intcount=helper.ExecuteSQLReturnInt(sql,pars,CommandType.Text);if(count>0)this.dataGridView1.DataSource=helper.SelectSqlReturnDataSet("select*fromstudent").Tables[0];MessageBox.Show("添加成功");privatevoiddataGridView1_CellDoubleClick(objectsender,DataGridViewCellEventArgse)if(MessageBox.Show("是否刪除","刪除確認",MessageBoxButtons.OKCancel)==DialogResult.OK)stringsno=this.dataGridView1.CurrentRow.Cells["sno"].Value.ToString();stringcmdText="deletefromstudentwheresno=@sno";SqlParameter[]pars=newSqlParameter[]{newSqlParameter("@sno",sno)};intcount=helper.ExecuteSQLReturnInt(cmdText,pars,CommandType.Text);if(count>0)this.dataGridView1.DataSource=helper.SelectSqlReturnDataSet("select*fromstudent").Tables[0];MessageBox.Show("刪除成功");privatevoidbindData()this.tbSno.Text=this.dataGridView1.CurrentRow.Cells["sno"].Value.ToString();this.tbSname.Text=this.dataGridView1.CurrentRow.Cells["sname"].Value.ToString();this.tbSsex.Text=this.dataGridView1.CurrentRow.Cells["ssex"].Value.ToString();privatevoidbtUpdate_Click(objectsender,EventArgse)stringsno=this.dataGridView1.CurrentRow.Cells["sno"].Value.ToString();stringcmdText="updatestudentsetsname=@sname,ssex=@ssexwheresno=@sno";SqlParameter[]pars=newSqlParameter[]newSqlParameter("@sno",sno),newSqlParameter("@sname",this.tbSname.Text),newSqlParameter("@ssex",this.tbSsex.Text)intcount=helper.ExecuteSQLReturnInt(cmdText,pars,CommandType.Text);if(count>0)this.dataGridView1.DataSource=helper.SelectSqlReturnDataSet("select*fromstudent").Tables[0];MessageBox.Show("更新成功");Forml.DesignernamespaceWinStuDBpartialclassForm1///必需的設(shè)計器變量。privateSystem.ComponentModel.IContainercomponents=null;///清理所有正在使用的資源。///<paramname="disposing">如果應(yīng)釋放托管資源,為true;否則為false。</param>protectedoverridevoidDispose(booldisposing)if(disposing&&(components!=null)){components.Dispose();}base.Dispose(disposing);#regionWindows窗體設(shè)計器生成的代碼///設(shè)計器支持所需的方法-不要///使用代碼編輯器修改此方法的內(nèi)容。privatevoidInitializeComponent()this.dataGridView1=newSystem.Windows.Forms.DataGridView();this.groupBox1=newSystem.Windows.Forms.GroupBox();this.label1=newSystem.Windows.Forms.Label();this.tbSno=newSystem.Windows.Forms.TextBox();this.姓名=newSystem.Windows.Forms.Label();this.tbSname=newSystem.Windows.Forms.TextBox();this.label2=newSystem.Windows.Forms.Label();this.tbSsex=newSystem.Windows.Forms.TextBox();this.btAdd=newSystem.Windows.Forms.Button();this.btUpdate=newSystem.Windows.Forms.Button();((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();this.groupBox1.SuspendLayout();this.SuspendLayout();//dataGridView1this.dataGridView1.ColumnHeadersHeightSizeMode=System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;this.dataGridView1.Location=newSystem.Drawing.Point(0,0);this.dataGridView1.Name="dataGridView1";this.dataGridView1.RowTemplate.Height=23;this.dataGridView1.Size=newSystem.Drawing.Size(450,180);this.dataGridView1.TabIndex=0;this.dataGridView1.CellDoubleClick+=newSystem.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellDoubleClick);this.dataGridView1.CellClick+=newSystem.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellClick);//groupBox1this.groupBox1.Controls.Add(this.tbSsex);this.groupBox1.Controls.Add(this.label2);this.groupBox1.Controls.Add(this.tbSname);this.groupBox1.Controls.Add(this.姓名);this.groupBox1.Controls.Add(this.tbSno);this.groupBox1.Controls.Add(this.label1);this.groupBox1.Location=newSystem.Drawing.Point(12,186);this.groupBox1.Name="groupBox1";this.groupBox1.Size=newSystem.Drawing.Size(213,136);this.groupBox1.TabIndex=1;this.groupBox1.TabStop=false;this.groupBox1.Text="groupBox1";//label1this.label1.AutoSize=true;this.label1.Location=newSystem.Drawing.Point(12,26);this.label1.Name="label1";this.label1.Size=newSystem.Drawing.Size(29,12);this.label1.TabIndex=0;this.label1.Text="學(xué)號";//tbSnothis.tbSno.Location=newSystem.Drawing.Point(47,20);this.tbSno.Name="tbSno";this.tbSno.Size=newSystem.Drawing.Size(100,21);this.tbSno.TabIndex=1;//姓名this.姓名.AutoSize=true;this.姓名.Location=newSystem.Drawing.Point(12,64);this.姓名.Name="姓名";this.姓名.Size=newSystem.Drawing.Size(29,12);this.姓名.TabIndex=2;this.姓名.Text="姓名";//tbSnamethis.tbSname.Location=newSystem.Drawing.Point(47,61);this.tbSname.Name="tbSname";this.tbSname.Size=newSystem.Drawing.Size(100,21);this.tbSname.TabIndex=3;//label2this.label2.AutoSize=true;this.label2.Location=newSystem.Drawing.Point(12,103);this.label2.Name="label2";this.label2.Size=newSystem.Drawing.Size(29,12);this.label2.TabIndex=4;this.label2.Text="性別";//tbSsexthis.tbSsex.Location=newSystem.Drawing.Point(47,100);this.tbSsex.Name="tbSsex";this.tbSsex.Size=newSystem.Drawing.Size(100,21);this.tbSsex.TabIndex=5;//btAddthis.btAdd.Location=newSystem.Drawing.Point(255,201);this.btAdd.Name="btAdd";this.btAdd.Size=newSystem.Drawing.Size(75,23);this.btAdd.TabIndex=2;this.btAdd.Text="添加";this.btAdd.UseVisualStyleBackColor=true;this.btAdd.Click+=newSystem.EventHandler(this.btAdd_Click);//btUpdatethis.btUpdate.Location=newSystem.Drawing.Point(255,239);this.btUpdate.Name="btUpdate";this.btUpdate.Size=newSystem.Drawing.Size(75,23);this.btUpdate.TabIndex=3;this.btUpdate.Text="修改";this.btUpdate.UseVisualStyleBackColor=true;this.btUpdate.Click+=newSystem.EventHandler(this.btUpdate_Click);//Form1this.AutoScaleDimensions=newSystem.Drawing.SizeF(6F,12F);this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;this.ClientSize=newSystem.Drawing.Size(451,334);this.Controls.Add(this.btUpdate);this.Controls.Add(this.btAdd);this.Controls.Add(this.groupBox1);this.Controls.Add(this.dataGridView1);this.Name="Form1";this.Text="Form1";this.Load+=newSystem.EventHandler(this.Form1_Load);((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();this.groupBox1.ResumeLayout(false);this.groupBox1.PerformLayout();this.ResumeLayout(false);#endregionprivateSystem.Windows.Forms.DataGridViewdataGridView1;privateSystem.Windows.Forms.GroupBoxgroupBox1;privateSystem.Windows.Forms.Labellabel1;privateSystem.Windows.Forms.Labellabel2;privateSystem.Windows.Forms.TextBoxtbSname;privateSystem.Windows.Forms.Label姓名;privateSystem.Windows.Forms.TextBoxtbSno;privateSystem.Windows.Forms.TextBoxtbSsex;privateSystem.Windows.Forms.ButtonbtAdd;privateSystem.Windows.Forms.ButtonbtUpdate;ProgramusingSystem;usingSystem.Collections.Generic;usingSystem.Windows.Forms;namespaceWinStuDBstaticclassProgram///應(yīng)用程序的主入口點。[STAThread]staticvoidMain()Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(newForm1());SqlHelperusingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Data;usingSystem.Data.SqlClient;usingSystem.Configuration;namespaceWinStuDBpublicclassSqlHelper//privatestringmyConnString;publicstringMyConnStringget{returnSystem.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString.ToString();///根據(jù)select語句返回dataset///<returns>dataset</returns>publicDataSetSelectSqlReturnDataSet(stringsql)SqlConnectionconn=newSqlConnection(MyConnString);SqlDataAdaptersda=newSqlDataAdapter(sql,conn);DataSetds=newDataSet();sda.Fill(ds);returnds;publicDataSetSelectSqlReturnDataSet(stringsql,SqlParameter[]pars,CommandTypetype)SqlConnectionconn=newSqlConnection(MyConnString);SqlDataAdaptersda=newSqlDataAdapter(sql,conn);if(pars!=null&&pars.Length>0)foreach(SqlParameterpinpars){sda.SelectCommand.Parameters.Add(p);}sda.SelectCommand.CommandType=type;DataSetds=newDataSet();sda.Fill(ds);returnds;publicintExecuteSQLReturnInt(stringsql,SqlParameter[]pars,CommandTypetype)SqlConnectionconn=newSqlConnection(MyConnString);trySqlCommandcmd=newSqlCommand(sql,conn);if(conn.State==ConnectionState.Broken||conn.State==ConnectionState.Closed){conn.Open();}if(pars!=null&&pars.Length>0)foreach(SqlParameterpinpars){cmd.Parameters.Add(p);}cmd.CommandType=CommandType.Text;intcount=cmd.ExecuteNonQuery();returncount;catch(Exceptionex){return0;}finally{conn.Close();}//publicSqlDataReaderSelectSqlReturnDatareader(stringsql,SqlParameter[]pars,CommandTypetype)//SqlConnectionconn=newSqlConnection(MyConnString);//SqlCommandcmd=newSqlCommand(sql,conn);//if(pars!=null&&pars.Length>0)//foreach(SqlParameterpinpars)//
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 摘草莓合同協(xié)議
- 雙方合同底賬協(xié)議
- 合資股東協(xié)議合同
- 瑜伽館試用期合同協(xié)議
- 孩子考試協(xié)議合同
- 出租車司機合同協(xié)議范本
- 山地養(yǎng)殖合同協(xié)議
- 酒店加盟協(xié)議合同
- 協(xié)議變更合同未達成一致
- 行政合同和協(xié)議
- 產(chǎn)品設(shè)計研發(fā)費用統(tǒng)計表
- 提高教學(xué)管理質(zhì)量校長講話:“2574”工作實施思路!即兩大抓手五項重點任務(wù)七個落實環(huán)節(jié)四個質(zhì)量目標
- 2025屆廣東省深圳市高三年級第一次調(diào)研考試歷史試題
- 清理報廢漁船合同范本
- 2023數(shù)據(jù)中心節(jié)能改造實踐案例
- 《基于西門子S7-1200PLC的四層電梯控制系統(tǒng)設(shè)計》8900字
- 生產(chǎn)安全事故應(yīng)急演練評估報告模版
- 退伍軍人心理培訓(xùn)課件
- 政治-湖南省長郡二十校聯(lián)盟2025屆新高考教學(xué)教研聯(lián)盟高三第一次聯(lián)考(長郡二十校一聯(lián))試題和答案
- 骨干教師培訓(xùn)與示范課實施計劃
- 《建筑工程施工索賠與應(yīng)對策略》課件
評論
0/150
提交評論