c#如何使用oledb连接TXT文件,并使用oledbdatareader读取文本文件内容到textbox控件中?

qq_36018745 2017-10-14 02:57:40
问题如标题。初学者,感谢!!
...全文
169 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuxiaol2 2017-10-20
  • 打赏
  • 举报
回复
oledb 是用来连接ACCESS的
qq_36018745 2017-10-19
  • 打赏
  • 举报
回复
引用 1 楼 无情时尚的回复:
读txt用File、StreamReader、FileStream,比较方便
感谢!只是想用oledb试试。
无情时尚 2017-10-14
  • 打赏
  • 举报
回复
读txt用File、StreamReader、FileStream,比较方便
/* API精灵 FOR C# 开始设计日期 2004.03.06 设计目的:简单快速对C#使用的API函数进行查询,并给出调用代码 设计进度: 2004.03.09 完成对的查询功能,包括 代码调用,文注释,所需的DLL库,与C#函数对应关系 2004.03.10 0:48:52 完成了用StringBuilder数组对原ComboBox的替换,可以使程序不用从新读取数据库就可以刷新修改后的信息! 2004.03.10 18:00:00 完成了用ArrayList对StringBuilder数组的替换节省2M内存 2004.03.11 21:10:15 完成滚动字幕的设置,启用了一个TIMER件,然后设置时间,删除字符串的第一个字母已达到滚动效果! 2004.03.11 22:02:00 改正更新时出现空值出错问题,新填函数isnull 2004.03.12 13:22:08 完成关键字高亮显示 高亮显示函数 mykeywords 2004.03.12 22:08:20 加强了高亮显示函数 mykeywords的功能,使其能识别不同的关键字并显示不同的颜色 2004.03.14 01:40:00 完成对CONST的查询,并且增加了 mykeywords1函数,使其关键字显示性能提高 2004.03.14 13:12:00 添加了提示信息,提示信息设置在函数 mytips() 2004.03.15 21:51:20 更改数据库和WINAPI.TXT路径为程序运行路径 2004.03.15 22:31:50 添加了鼠标右键信息 2004.03.15 23.23:30 添加了数据库密码 2004.03.16 23:24:30 添加了版权信息以及相应提示 */ using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Data.OleDb; using System.Runtime.InteropServices; using System.IO; namespace API精灵 { /// /// Form1 的摘要说明。 /// 这个版本没有使用oleDbDataAdapter+DataSet对数据进行存取,而是使用OleDbCommand +OleDbDataReader 的形式。 /// 主要是想试验一下不用oleDbDataAdapter+DataSet的数据存取速度。 /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button button1; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.Button button4; private System.Windows.Forms.TextBox mysearch; private System.Windows.Forms.ListBox tiplist; private System.Windows.Forms.ComboBox select_type; private System.Windows.Forms.TextBox dlltext; /// /// 必需的设计器变量。 /// //自定义变量 private ArrayList fundll = new ArrayList();//保存读取出来的DLL内容 private ArrayList funtips = new ArrayList();//保存读取出来的文提示信息 private ArrayList funcode = new ArrayList();//保存读取出来的C#调用代码 private ArrayList funmat = new ArrayList();//保存读取出来的C#对应函数 private ArrayList funwin9x = new ArrayList();//保存读取出来的WIN9X private ArrayList funwin2k = new ArrayList();//保存读取出来的WIN2K private int nowselect = 0; private string oldscoll_text; private int nowtypeselect = 0; private string nowpath = @System.Environment.CurrentDirectory+@"\"; private string dbpassword = "ling_feng_work"; public string myConnstr; public OleDbConnection myconn ;//创建一个新连接 private string mysql ;//查询语句 private string sql_update; private System.Windows.Forms.RichTextBox tipsmemo; private System.Windows.Forms.TextBox mat_text; private OleDbCommand mycommand = new OleDbCommand(); private System.Windows.Forms.RichTextBox codememo; private System.Windows.Forms.GroupBox groupBox4; private System.Windows.Forms.CheckBox win9x; private System.Windows.Forms.GroupBox groupBox5; private System.Windows.Forms.CheckBox win2k; private System.Windows.Forms.CheckBox e_add; private System.Windows.Forms.CheckBox e_modify; private System.Windows.Forms.Button b_modify; private System.Windows.Forms.Button b_add; private System.Windows.Forms.Timer timer1; private System.Windows.Forms.ToolTip toolTip1; private System.Windows.Forms.ContextMenu mypop; private System.Windows.Forms.MenuItem menuItem1; private System.ComponentModel.IContainer components; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// /// 清理所有正在使用的资源。 /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1)); this.button1 = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.tiplist = new System.Windows.Forms.ListBox(); this.select_type = new System.Windows.Forms.ComboBox(); this.mat_text = new System.Windows.Forms.TextBox(); this.mysearch = new System.Windows.Forms.TextBox(); this.dlltext = new System.Windows.Forms.TextBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.tipsmemo = new System.Windows.Forms.RichTextBox(); this.mypop = new System.Windows.Forms.ContextMenu(); this.menuItem1 = new System.Windows.Forms.MenuItem(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.codememo = new System.Windows.Forms.RichTextBox(); this.b_modify = new System.Windows.Forms.Button(); this.b_add = new System.Windows.Forms.Button(); this.button4 = new System.Windows.Forms.Button(); this.groupBox4 = new System.Windows.Forms.GroupBox(); this.win2k = new System.Windows.Forms.CheckBox(); this.win9x = new System.Windows.Forms.CheckBox(); this.groupBox5 = new System.Windows.Forms.GroupBox(); this.e_add = new System.Windows.Forms.CheckBox(); this.e_modify = new System.Windows.Forms.CheckBox(); this.timer1 = new System.Windows.Forms.Timer(this.components); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); this.groupBox4.SuspendLayout(); this.groupBox5.SuspendLayout(); this.SuspendLayout(); // // button1 // this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button1.Location = new System.Drawing.Point(224, 395); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 24); this.button1.TabIndex = 10; this.button1.Text = "关 于"; this.button1.Click += new System.EventHandler(this.button1_Click); // // groupBox1 // this.groupBox1.Controls.Add(this.tiplist); this.groupBox1.Controls.Add(this.select_type); this.groupBox1.Controls.Add(this.mat_text); this.groupBox1.Controls.Add(this.mysearch); this.groupBox1.Controls.Add(this.dlltext); this.groupBox1.Location = new System.Drawing.Point(8, 8); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(200, 168); this.groupBox1.TabIndex = 1; this.groupBox1.TabStop = false; this.groupBox1.Text = "API查询"; // // tiplist // this.tiplist.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tiplist.ItemHeight = 12; this.tiplist.Location = new System.Drawing.Point(8, 43); this.tiplist.Name = "tiplist"; this.tiplist.Size = new System.Drawing.Size(184, 110); this.tiplist.TabIndex = 1; this.tiplist.Visible = false; this.tiplist.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tiplist_KeyDown); this.tiplist.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tiplist_KeyPress); this.tiplist.DoubleClick += new System.EventHandler(this.tiplist_DoubleClick); this.tiplist.MouseUp += new System.Windows.Forms.MouseEventHandler(this.tiplist_MouseUp); this.tiplist.MouseLeave += new System.EventHandler(this.tiplist_MouseLeave); this.tiplist.SelectedIndexChanged += new System.EventHandler(this.tiplist_SelectedIndexChanged); // // select_type // this.select_type.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.select_type.Items.AddRange(new object[] { "API函数查询", "常量定义查询"}); this.select_type.Location = new System.Drawing.Point(8, 61); this.select_type.Name = "select_type"; this.select_type.Size = new System.Drawing.Size(184, 20); this.select_type.TabIndex = 2; this.select_type.SelectedIndexChanged += new System.EventHandler(this.select_type_SelectedIndexChanged); // // mat_text // this.mat_text.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.mat_text.Location = new System.Drawing.Point(8, 134); this.mat_text.Name = "mat_text"; this.mat_text.Size = new System.Drawing.Size(184, 21); this.mat_text.TabIndex = 4; this.mat_text.Text = "C#对应函数:"; this.mat_text.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mat_text_MouseDown); // // mysearch // this.mysearch.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.mysearch.Location = new System.Drawing.Point(8, 24); this.mysearch.Name = "mysearch"; this.mysearch.Size = new System.Drawing.Size(184, 21); this.mysearch.TabIndex = 0; this.mysearch.Text = ""; this.mysearch.KeyDown += new System.Windows.Forms.KeyEventHandler(this.mysearch_KeyDown); this.mysearch.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mysearch_MouseDown); this.mysearch.TextChanged += new System.EventHandler(this.mysearch_TextChanged); // // dlltext // this.dlltext.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.dlltext.Location = new System.Drawing.Point(8, 97); this.dlltext.Name = "dlltext"; this.dlltext.Size = new System.Drawing.Size(184, 21); this.dlltext.TabIndex = 3; this.dlltext.Text = ""; this.dlltext.TextChanged += new System.EventHandler(this.dlltext_TextChanged); // // groupBox2 // this.groupBox2.Controls.Add(this.tipsmemo); this.groupBox2.Location = new System.Drawing.Point(216, 8); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(200, 168); this.groupBox2.TabIndex = 2; this.groupBox2.TabStop = false; this.groupBox2.Text = "函数注释"; // // tipsmemo // this.tipsmemo.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.tipsmemo.ContextMenu = this.mypop; this.tipsmemo.Location = new System.Drawing.Point(8, 16); this.tipsmemo.Name = "tipsmemo"; this.tipsmemo.Size = new System.Drawing.Size(184, 144); this.tipsmemo.TabIndex = 0; this.tipsmemo.Text = ""; this.tipsmemo.MouseEnter += new System.EventHandler(this.richTextBox1_MouseEnter); // // mypop // this.mypop.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.menuItem1}); // // menuItem1 // this.menuItem1.Index = 0; this.menuItem1.Text = "复制信息"; this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click); // // groupBox3 // this.groupBox3.Controls.Add(this.codememo); this.groupBox3.Location = new System.Drawing.Point(8, 221); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(408, 168); this.groupBox3.TabIndex = 3; this.groupBox3.TabStop = false; this.groupBox3.Text = "代码调用"; // // codememo // this.codememo.ContextMenu = this.mypop; this.codememo.Location = new System.Drawing.Point(8, 16); this.codememo.Name = "codememo"; this.codememo.Size = new System.Drawing.Size(392, 144); this.codememo.TabIndex = 0; this.codememo.Text = ""; this.codememo.TextChanged += new System.EventHandler(this.codememo_TextChanged); // // b_modify // this.b_modify.Enabled = false; this.b_modify.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.b_modify.Location = new System.Drawing.Point(120, 395); this.b_modify.Name = "b_modify"; this.b_modify.Size = new System.Drawing.Size(75, 24); this.b_modify.TabIndex = 4; this.b_modify.Text = "修改信息"; this.b_modify.Click += new System.EventHandler(this.button2_Click); // // b_add // this.b_add.Enabled = false; this.b_add.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.b_add.Location = new System.Drawing.Point(16, 395); this.b_add.Name = "b_add"; this.b_add.Size = new System.Drawing.Size(75, 24); this.b_add.TabIndex = 5; this.b_add.Text = "添加新项"; // // button4 // this.button4.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.button4.Location = new System.Drawing.Point(328, 395); this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(75, 24); this.button4.TabIndex = 6; this.button4.Text = "退 出"; this.button4.Click += new System.EventHandler(this.button4_Click); // // groupBox4 // this.groupBox4.Controls.Add(this.win2k); this.groupBox4.Controls.Add(this.win9x); this.groupBox4.Location = new System.Drawing.Point(8, 176); this.groupBox4.Name = "groupBox4"; this.groupBox4.Size = new System.Drawing.Size(200, 40); this.groupBox4.TabIndex = 11; this.groupBox4.TabStop = false; // // win2k // this.win2k.Location = new System.Drawing.Point(104, 11); this.win2k.Name = "win2k"; this.win2k.Size = new System.Drawing.Size(80, 24); this.win2k.TabIndex = 1; this.win2k.Text = "支持win2k"; // // win9x // this.win9x.Location = new System.Drawing.Point(16, 11); this.win9x.Name = "win9x"; this.win9x.TabIndex = 0; this.win9x.Text = "支持win9x"; // // groupBox5 // this.groupBox5.Controls.Add(this.e_add); this.groupBox5.Controls.Add(this.e_modify); this.groupBox5.Location = new System.Drawing.Point(216, 176); this.groupBox5.Name = "groupBox5"; this.groupBox5.Size = new System.Drawing.Size(200, 40); this.groupBox5.TabIndex = 12; this.groupBox5.TabStop = false; // // e_add // this.e_add.Location = new System.Drawing.Point(112, 10); this.e_add.Name = "e_add"; this.e_add.Size = new System.Drawing.Size(80, 24); this.e_add.TabIndex = 5; this.e_add.Text = "允许添加"; this.e_add.CheckedChanged += new System.EventHandler(this.e_add_CheckedChanged); // // e_modify // this.e_modify.Location = new System.Drawing.Point(16, 10); this.e_modify.Name = "e_modify"; this.e_modify.Size = new System.Drawing.Size(76, 24); this.e_modify.TabIndex = 4; this.e_modify.Text = "允许修改"; this.e_modify.CheckedChanged += new System.EventHandler(this.e_modify_CheckedChanged); // // timer1 // this.timer1.Interval = 500; this.timer1.Tick += new System.EventHandler(this.timer1_Tick); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(424, 429); this.Controls.Add(this.groupBox5); this.Controls.Add(this.groupBox4); this.Controls.Add(this.button4); this.Controls.Add(this.b_add); this.Controls.Add(this.b_modify); this.Controls.Add(this.groupBox3); this.Controls.Add(this.groupBox1); this.Controls.Add(this.button1); this.Controls.Add(this.groupBox2); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.MaximizeBox = false; this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "API精灵FOR C#"; this.Load += new System.EventHandler(this.Form1_Load); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox3.ResumeLayout(false); this.groupBox4.ResumeLayout(false); this.groupBox5.ResumeLayout(false); this.ResumeLayout(false); } #endregion /// /// 应用程序的主入口点。 /// [STAThread] static void Main() { Application.Run(new Form1()); } [DllImport("user32.dll", EntryPoint="ShowWindow")] public static extern int ShowWindow ( int hwnd, int nCmdShow ); private void button1_Click(object sender, System.EventArgs e) { AboutForm myabout = new AboutForm(); myabout.ShowDialog(); } /// /// 填写mysearch内容。 /// private void search_comp() { if (tiplist.SelectedIndex>-1) mysearch.Text = tiplist.SelectedItem.ToString(); tiplist.Visible = false ; mysearch.Select(); } /// /// 自动填写提示内容。 /// private void autocomp() { if (tiplist.SelectedIndex>-1) try { if (this.nowtypeselect==0) //================查询函数 { this.nowselect = tiplist.SelectedIndex; dlltext.Text = fundll[tiplist.SelectedIndex].ToString();//else tipsmemo.Text = funtips[tiplist.SelectedIndex].ToString(); codememo.Text = funcode[tiplist.SelectedIndex].ToString(); mat_text.Text = funmat[tiplist.SelectedIndex].ToString(); this.oldscoll_text = mat_text.Text; if (funwin9x[tiplist.SelectedIndex].ToString()==("Yes")) win9x.Checked=true; else win9x.Checked=false; if (funwin2k[tiplist.SelectedIndex].ToString()==("Yes")) win2k.Checked=true; else win2k.Checked=false; //滚动文字 if (mat_text.TextLength>30) timer1.Enabled = true; else timer1.Enabled = false; } else { dlltext.Text = ""; tipsmemo.Text = ""; codememo.Text = ""; win9x.Checked = false; win2k.Checked = false; } //******************** if (this.nowtypeselect==1) { this.nowselect = tiplist.SelectedIndex; codememo.Text = funcode[tiplist.SelectedIndex].ToString(); } //******************** //================= } catch { dlltext.Text = "没有找到相应连接库"; tipsmemo.Text = "没有找到相应提示"; codememo.Text = "没有找到相应调用代码"; mat_text.Text = "没有找到相应C#函数"; } } // /// /// 手动释放一些内存。 /// private void mydisp() { tipsmemo.Clear(); codememo.Clear(); tiplist.Items.Clear(); // ===== fundll.Clear();//保存读取出来的DLL内容 funtips.Clear();//保存读取出来的文提示信息 funcode.Clear();//保存读取出来的C#调用代码 funmat.Clear();//保存读取出来的C#对应函数 funwin9x.Clear();//保存读取出来的WIN9X funwin2k.Clear();//保存读取出来的WIN2K } private void mysearch_TextChanged(object sender, System.EventArgs e) { tiplist.Visible = true ; //自动完成功能。 tiplist.SelectedIndex = (tiplist.FindString(mysearch.Text,-1)) ;//加上这句,保证TIPLIST跟着自动变化 nowselect = tiplist.SelectedIndex; autocomp(); //设置提示信息 mytips(); } private void mysearch_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if ((e.KeyCode == Keys.Down) || (e.KeyCode == Keys.Up)) tiplist.Focus(); if (e.KeyCode == Keys.Enter) { search_comp(); if (this.nowtypeselect==0) mykeyword(); if (this.nowtypeselect==1) mykeyword1(); } if (e.KeyCode == Keys.Escape) { tiplist.Visible = false ; } } private void tiplist_MouseLeave(object sender, System.EventArgs e) { } private void tiplist_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) { } private void tiplist_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.search_comp(); if (this.nowtypeselect==0) mykeyword(); else mykeyword1(); } if (e.KeyCode == Keys.Escape) { tiplist.Visible = false ; } } private void tiplist_DoubleClick(object sender, System.EventArgs e) { this.search_comp(); if (this.nowtypeselect==0) mykeyword(); else mykeyword1(); } private void Form1_Load(object sender, System.EventArgs e) { //初始化数据库 initdatabase(); //MessageBox.Show(this,"欢迎使用 共享版\n 本版对使用功能上略有限制\n 且不提供数据库更新!\n 如想获得更多信息请与我联系。\n dong_teng@tom.com","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); select_type.SelectedIndex = 0; AboutForm myabout = new AboutForm(); myabout.ShowDialog(); } // private void mytips() { //设置提示信息 if ((this.nowselect>-1)&(this.nowtypeselect==0)) { toolTip1.SetToolTip(this.dlltext,"所在动态连接库: "+this.fundll[this.nowselect].ToString()); toolTip1.SetToolTip(this.mat_text,"在C#对应的函数: "+this.funmat[this.nowselect].ToString()); toolTip1.SetToolTip(this.codememo,"函数 "+this.tiplist.SelectedItem.ToString()+" 在C#的调用代码,可以手动修改"); toolTip1.SetToolTip(this.tipsmemo,"函数 "+this.tiplist.SelectedItem.ToString()+" 的注释信息,可以手动修改"); } else if ((this.nowselect>-1)&(this.nowtypeselect==1)) { toolTip1.SetToolTip(this.codememo,"常量 "+this.tiplist.SelectedItem.ToString()+" 在C#的调用代码"); toolTip1.SetToolTip(this.dlltext,"没有相关信息"); toolTip1.SetToolTip(this.mat_text,"没有相关信息"); toolTip1.SetToolTip(this.tipsmemo,"没有相关信息"); } } // private void initdatabase() { string dbpath = @nowpath+"winapi.mdb"; tiplist.Items.Clear(); //@"Provider=Microsoft.Jet.OleDB.4.0;Data Source="+dbpath+";User Id=admin;Password="+this.dbpassword ; //"Provider=Microsoft.Jet.OleDB.4.0;Data Source=your mdb filename;Jet OLEDB:Database Password='pass'" ; this.myConnstr = @"Provider=Microsoft.Jet.OleDB.4.0;Data Source="+dbpath+";User Id=admin;Jet OLEDB:Database Password="+this.dbpassword ; this.myconn= new OleDbConnection(myConnstr); mysql= @"select Fun_name,Fun_dll,Fun_tips,Fun_code,Fun_com,win9x,win2k from winapi"; using(myconn) { myconn.Open(); // if (myconn.State.ToString() == "Open") MessageBox.Show("打开成功!"); //数据处理 // OleDbCommand mycommand = new OleDbCommand(mysql,myconn); mycommand.CommandText = mysql; mycommand.Connection = myconn; OleDbDataReader myreader = mycommand.ExecuteReader(); int i=0; while (myreader.Read()) { tiplist.Items.Add(myreader["Fun_name"]); fundll.Add(myreader["fun_dll"].ToString()); funtips.Add(myreader["fun_tips"].ToString()); funcode.Add(myreader["fun_code"].ToString()); funmat.Add(myreader["fun_com"].ToString()); funwin9x.Add(myreader["win9x"].ToString()); funwin2k.Add(myreader["win2k"].ToString()); i++; } myconn.Close(); myreader.Close(); } } //更新缓存 private void memo_update() { fundll[nowselect] = dlltext.Text; funtips[nowselect] = this.tipsmemo.Text; funcode[nowselect] = this.codememo.Text; funmat[nowselect] = this.mat_text.Text; if (win9x.Checked) funwin9x[nowselect]="Yes" ;else funwin9x[nowselect]="No"; if (win2k.Checked) funwin2k[nowselect]="Yes" ;else funwin2k[nowselect]="No"; } // private void oleDbConnection1_InfoMessage(object sender, System.Data.OleDb.OleDbInfoMessageEventArgs e) { } //==============从WINAPI.TXT读取CONST并拆分 private void mysplip() { //string dbpath = @System.Environment.CurrentDirectory+@"\winapi.mdb"; string filename =@nowpath +"winapi.txt"; string nextline; tiplist.Items.Clear(); StreamReader sr = new StreamReader(filename); while ((nextline = sr.ReadLine())!=null) { if (nextline.StartsWith("public const")) { string[] ss = nextline.Split('='); tiplist.Items.Add(ss[0].Substring(16).Trim()); funcode.Add(nextline); } } sr.Close(); } //============================== private void select_type_SelectedIndexChanged(object sender, System.EventArgs e) { if (select_type.SelectedIndex != this.nowtypeselect) { this.mydisp(); switch (select_type.SelectedIndex) { case 0:initdatabase();this.nowtypeselect=select_type.SelectedIndex;break; case 1:mysplip();this.nowtypeselect=select_type.SelectedIndex;this.dlltext.Clear();this.mat_text.Clear();break; } isenable(this.nowtypeselect); } } private void dlltext_TextChanged(object sender, System.EventArgs e) { } private void richTextBox1_MouseEnter(object sender, System.EventArgs e) { tiplist.Visible = false ; } private void mysearch_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { tiplist.Visible = false ; mysearch.Focus(); } private void tiplist_SelectedIndexChanged(object sender, System.EventArgs e) { autocomp(); } /// /// 修改内容。 /// private void fun_update() { using(myconn) { myconn.ConnectionString = myConnstr; myconn.Open(); try { //if (myconn.State.ToString() == "Open") MessageBox.Show("打开成功!"); isnull();//判断是否有无效值 string str_win9x,str_win2k; if (win9x.Checked) str_win9x = "Yes" ; else str_win9x = "No"; if (win2k.Checked) str_win2k = "Yes" ; else str_win2k = "No"; sql_update = "update winapi set Fun_dll = '"+dlltext.Text+"'"+" , Fun_tips = '"+tipsmemo.Text+"'"+" , Fun_code = '"+codememo.Text+"'"+" , Fun_com ='"+mat_text.Text+"' "; sql_update +=" , win9x = '" + str_win9x +"' " + ", win2k = '" + str_win2k+"' "; sql_update +=" where Fun_name ='"+ mysearch.Text+"'"; mycommand.Connection = myconn; mycommand.CommandText = sql_update; mycommand.ExecuteNonQuery(); myconn.Close(); memo_update(); MessageBox.Show(this,"恭喜!更新成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information); } catch { // tipsmemo.Text = sql_update; MessageBox.Show("没有找到相应记录,更新失败!"); } } } //判断是更新的部分是否有效(不能为空) private void isnull() { if (this.mat_text.Text=="") this.mat_text.Text="没有相关信息"; if (this.codememo.Text=="") this.codememo.Text="没有相关信息"; if (this.tipsmemo.Text=="") this.tipsmemo.Text="没有相关信息"; if (this.dlltext.Text=="") this.dlltext.Text="没有相关信息"; } //关键字高亮显示 private void mykeyword() { string[] keywords = new string[5]; keywords[0]=mysearch.Text; keywords[1]="string"; keywords[2]="ref"; keywords[3]="int"; keywords[4]="static extern"; for(int i=0;i0) { index++; switch(i) { case 0: codememo.SelectionColor = Color.Red;break; case 1: codememo.SelectionColor = Color.Green;break; case 2: codememo.SelectionColor = Color.Brown;break; case 3: codememo.SelectionColor = Color.Blue;break; case 4: codememo.SelectionColor = Color.Green;break; //default:codememo.SelectionColor = Color.Blue;break; } } } } // //CONST关键字高亮显示 private void mykeyword1() { string[] keywords = new string[5]; keywords[0]=mysearch.Text; keywords[1]="="; keywords[2]="0"; keywords[3]="int"; keywords[4]="const"; for(int i=0;i0) { index++; switch(i) { case 0: codememo.SelectionColor = Color.Red;break; case 1: codememo.SelectionColor = Color.Blue;break; case 2: codememo.SelectionColor = Color.Green;break; case 3: codememo.SelectionColor = Color.Blue;break; case 4: codememo.SelectionColor = Color.Green;break; //default:codememo.SelectionColor = Color.Blue;break; } if (index>codememo.TextLength) break; } } } // private void button2_Click(object sender, System.EventArgs e) { this.fun_update(); } private void isenable(int i_temp) { if (i_temp==0) { win9x.Enabled=true; win2k.Enabled=true; e_modify.Enabled=true; e_add.Enabled=true; b_modify.Enabled=true; b_add.Enabled=true; } else { win9x.Enabled=false; win2k.Enabled=false; e_modify.Enabled=false; e_add.Enabled=false; b_modify.Enabled=false; b_add.Enabled=false; } } private void button4_Click(object sender, System.EventArgs e) { Application.Exit(); } private void e_modify_CheckedChanged(object sender, System.EventArgs e) { if (e_modify.Checked) b_modify.Enabled = true; else b_modify.Enabled = false; } private void e_add_CheckedChanged(object sender, System.EventArgs e) { if (e_add.Checked) b_add.Enabled = true; else b_add.Enabled = false; } private void timer1_Tick(object sender, System.EventArgs e) { if (this.mat_text.TextLength>0) mat_text.Text = mat_text.Text.Remove(0,1); else mat_text.Text = oldscoll_text; } private void mat_text_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { timer1.Enabled = false ; mat_text.Text = oldscoll_text; } private void codememo_TextChanged(object sender, System.EventArgs e) { } private void tiplist_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { } private void menuItem1_Click(object sender, System.EventArgs e) { Control ct = this.ActiveControl; string temp = ct.Text; Clipboard.SetDataObject(temp); } private void menuItem2_Click(object sender, System.EventArgs e) { } } }
第一天 我认为ASP.NET比ASP难很多,希望大家做好准备。难难在实现同一个效果有很多方法,大家或许会疑惑。十天学会系列教程会清晰的写出各种方法,让大家能少一点坎坷。在ASP里面,大家几乎都是使用VB,数据库嘛,也无非是SQL和ACCESS。在ASP.NET里面,数据库还是这两个但是常用的语言多了一个C#,也是微软推荐的语言,为.NET平台定制的语言。这样ASP.NET就有四种组合:VB+ACCESS,VB+SQL,C#+ACCESS,C#+SQL,本教程会使用C#+ACCESS,兼顾四种来写,让大家对ASP.NET有一个全面的认识。虽然说学习ASP.NET不需要任何ASP基础,但是我觉得如果大家ASP不会,还是先看一下【十天学会ASP教程】,大家所需要了解的不是ASP的程序怎么写,而是怎么构建服务器,怎么使用HTML表单,同时对SQL语句有一个基础和理解,因为在本文里我不会将将一些基础的东西。 废话不多说,开始我们第一天的学习: 学习目的:调试出安装环境 我要申明一点,操作系统就用2000,如果说要学习一个网络语言还不肯多装一个操作系统的话,那我看也不要学习了。 先到网上下载一个MDAC(要是2.7以上的版本才行),然后安装,安装以后或许会重新启动一次。 然后再下载一个.NET FRAMEWORK SDK,安装以后会在制面板里面的管理工具里面多两个东西,这个不用理睬他,我们要使用的还是原来的INTERNET服务管理器。打开它按照ASP教程里面的调试方法建立一个目录,建立一个EXAMPLE1.ASPX,然后用记事本打开这个文件在里面输入 <script language="c#" runat="server"> void Page_Load() { Response.Write("Hello World!"); } sub page_load() response.write("Hello World!") end sub 文件总是有A和B分别是用C#和VB写的,演示的图片就用C#那一种的,都一样嘛,教程里面代码也是写两种用
分割开,大家可以比较一下。2、我写教程的时候用的都是记事本来编写APS.NET大家也可以安装VS.NET来编写不过起步还是用记事本比较好,因为可以看的更加透彻一点。今天就说到这里,明天说一下C#的基本语法。 十天学会ASP.net(2) 作者:佚名 阅读人次:11611 文章来源:未知 发布时间:2005-6-24 网友评论(4)条 第二天 学习目的:掌握C#的基本知识 一、定义变量: string strExample; 字符串("aaa") char chrExample; 字符('a') bool blnExample; Bool型(true/false) DataTime datExample; 日期型("09/19/2002") int intExample; 整数(32位有符号整数) double dblExample; 浮点数(64位双精度浮点数) 二、各种运算: = 赋值运算 + 加法运算 - 减法运算 * 乘法运算 / 除法运算 % 取模运算 && 逻辑And || 逻辑Or ! 逻辑Not 三、各种结构: if(条件) { } else { } switch(条件) { case option1: break; case option2: break; } for(int i=1;i<=10;i++)//特别注意这里面是分号 { } while(条件) { } do { }while(条件); 四、注意事项: 1、用习惯VB的人很容易漏了语句末尾的分号; 2、用习惯VB的人很随便使用变量但是不申明,这在C#默认情况下是不允许的; 3、在向函数传递参数的时候要用圆括号:Response.Write "aa";是不允许的。 我说的这点几乎称不上是在说一种语言,一种语言的学习不仅仅需要学习语法,还需要学习语言特色,希望大家有空还是买一本C#的书来好好研究一下C#作为一种新的语言的特性吧。 十天学会ASP.net(2) 作者:佚名 阅读人次:11611 文章来源:未知 发布时间:2005-6-24 网友评论(4)条 第二天 学习目的:掌握C#的基本知识 一、定义变量: string strExample; 字符串("aaa") char chrExample; 字符('a') bool blnExample; Bool型(true/false) DataTime datExample; 日期型("09/19/2002") int intExample; 整数(32位有符号整数) double dblExample; 浮点数(64位双精度浮点数) 二、各种运算: = 赋值运算 + 加法运算 - 减法运算 * 乘法运算 / 除法运算 % 取模运算 && 逻辑And || 逻辑Or ! 逻辑Not 三、各种结构: if(条件) { } else { } switch(条件) { case option1: break; case option2: break; } for(int i=1;i<=10;i++)//特别注意这里面是分号 { } while(条件) { } do { }while(条件); 四、注意事项: 1、用习惯VB的人很容易漏了语句末尾的分号; 2、用习惯VB的人很随便使用变量但是不申明,这在C#默认情况下是不允许的; 3、在向函数传递参数的时候要用圆括号:Response.Write "aa";是不允许的。 我说的这点几乎称不上是在说一种语言,一种语言的学习不仅仅需要学习语法,还需要学习语言特色,希望大家有空还是买一本C#的书来好好研究一下C#作为一种新的语言的特性吧。 十天学会ASP.net(4) 作者:佚名 阅读人次:8772 文章来源:未知 发布时间:2005-6-24 网友评论(7)条 第四天 学习目的:掌握WEB件的使用(二) 首先我要说明,我这十天教程也只是一个让大家对ASP.NET有一个认识而已,我也跳过了很多东西。网上有很多人在责骂我写的教程,认为十天什么都学不会,看了我的教程还是什么都不会,我想他们或许是过高估计了我的教程。外面有很多书,关于ASP和ASP.NET的,我就是看外面的书学会的。我所要做的就是希望大家能看了我的教程以后觉得ASP和ASP.NET不是学不会的东西然后有信心去学会它。我想学习还是靠自己的,外面每一本书也有自己写的不周到的地方,关键还需要自己的实践加上探索。 首先来说一下表单的验证件,以前我们做表单验证,如果是客户端的JAVASCRIPT,不能做到美观统一,而且还可以通过直接在浏览器起教表单来屏蔽;如果我们做服务器端验证,又会发现让检验结果在前台反映也是很麻烦的事情。现在好了,ASP.NET提供的很多检验件让我们不需要考虑是客户端检验还是服务器端检验,让我们不需要考虑是怎么输出检验结果。 看一下检验表单件是不是填写了的检验件先: textbox id="username" runat="server" cssclass="textbox"/> controltovalidate就是你想检验的件的ID;默认情况下不显示错误消息,地方也会被保留,如果使用了display="dynamic" 那么不显示错误消息的地方不会被空出; forecolor="#ff0000" font-name="宋体" font-size="9pt" 就是设定错误消息字体的颜色,字体,大小的;text="请填写" 就是当没有填写内容时候显示的错误消息;别忘记最后的runat="server"。现在这个检验件是放在了textbox的后面,那么错误消息也在textbox后面显示,也可以放在其他地方。 再看一下比较表单件的数据与另外一个数据的检验件: textbox id="password1" runat="server" textmode="password" cssclass="textbox"/> 这里是第一个需要用户填写的密码框 我们经常会再设立一个密码框让用户再填写一次: textbox id="password2" runat="server" textmode="password" cssclass="textbox"/> controltocompare="password1" 就是需要比较的件;operator="equal" 就是设定比较操作是:是否相等(还有NotEqual:不相等,LessThan:少于,GreaterThan:大于,当不符合这个比较操作的时候显示错误消息)。 以前说到BUTTON件CausesValidation=true/false来设置按钮提交的表单是不是被检验也就是这里的几个检验件,如果CausesValidation=true的话按下按钮就会首先检测是不是都通过了检验件的检验。 下面再说两点: 一、每一个可以显示的件都有是不是显示的属性,比如username.Visible=false;就是隐藏了前面的username件;还有就是如果要对件应用CSS的话就这么写:cssclass="",而不是以前HTML的class=""。 二、所有WEB件都要包含在
,否则就会出错。 今天就到此结束,请继续往后面看,下次开始就要说ADO.NET了。 十天学会ASP.net(5) 作者:佚名 阅读人次:8013 文章来源:未知 发布时间:2005-6-24 网友评论(6)条 第五天 学习目的:学会连接两种数据库 对于ASP来说,我们常用的数据库无非是ACCESS和SQL SERVER,对于ASP.NET也是,不过ASP.NET对于SQL SERVER有专门的连接组件而不推荐用OLE DB。 首先看一下ACCESS的连接数据库并打开; string strConnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source="; strConnection+=Server.MapPath("*.mdb"); //*就是数据库的名字 OleDbConnection objConnection=new OleDbConnection(strConnection); objConnection.Open(); ________________________________________ dim objConnection as OleDbConnection objConnection=new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("*.mdb")) objConnection.Open() 下面再看一下SQL SERVER的连接数据库并打开; string strConnection="server=数据库连接;uid=用户名;pwd=密码;database=数据库名字"; SqlConnediob objConnection=new SqlCOnnection(strConnection); objConnection.Open(); ________________________________________ dim objConnection as SqlConnectiom objConnection=new SqlConnection("server=数据库连接;uid=用户名;pwd=密码;database=数据库名字") objConnection.Open() 实际上,在大多数地方SQL SERVER和ACCESS的区别除了连接语句,其他定义语句也就是SQL××和OLEDB××的区别 另外,如果是ACCESS数据库的话在ASPX文件的开头需要包括下列语句: <%@Import Namespace="System.Data"%> <%@Import Namespace="System.Data.OleDb"%> 如果是SQL SERVER则需要包括以下语句: <%@Import Namespace="System.Data"%> <%@Import Namespace="System.Data.SqlClient"%> 今天就说到这里,明天开始讲数据库的读取。 十天学会ASP.net(6) 作者:佚名 阅读人次:7634 文章来源:未知 发布时间:2005-6-24 网友评论(4)条 第六天 学习目的:学会读取数据库 有的网友说,不会C#,在ASP.NET里面还是选择VB.NET,这个我不反对,但是我觉得既然是学习新的东西,就不要在意有多少是新的。实际上C#就一般的操作来说,只是区分大小写和多了一个分号这两点与VB.NET不同其他都差不多啊。在ASP里面我们读取数据就直接用RECORDSET,然后在HTML代码里面穿插<%= %>就可以显示了,但是ASP.NET讲究的是代码分离,如果还是这样显示数据就不能代码分离了。所以我们有两种方法:如果是读取一条记录的数据或者不多的数据,我们用DATAREADER采集数据,然后赋值给LABEL件的Text属性即可;如果是读取大量数据我们就采用DATAGRID。 今天我们就来说一下DATAREADER: string strConnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source="; strConnection+=Server.MapPath(strDb); OleDbConnection objConnection=new OleDbConnection(strConnection); OleDbCommand objCommand = new OleDbCommand("这里是SQL语句" , objConnection); objConnection.Open(); OleDbDataReader objDataReader=objCommand.ExecuteReader(); if(objDataReader.Read()) { oicq.Text=Convert.ToString(objDataReader["useroicq"]); homesite.Text=Convert.ToString(objDataReader["usersite"]); face.SelectedItem.Text=Convert.ToString(objDataReader["userface"]); } 大家可以看到我们首先是连接数据库然后打开,对于select的命令,我们申明一个OleDbCommand来执行之,然后再申明一个OleDbDataReader,来读取数据,用的是ExecuteReader(),objDataReader.Read()就开始读取了,在输出的时候我们要注意Text属性接受的只能是字符串,所以我们要把读出的数据都转化为字符串才行。 转换变量类型函数: 转换为字符串:Convert.ToString() 转换为数字:Convert.ToInt64(),Convert.ToInt32(),Convert.ToInt16() 是按照数字位数由长到短 转换为日期:Convert.ToDateTime() ________________________________________ dim objConnection as OleDbConnection dim objCommand as OleDbCommand dim objDataReader as OleDbDataReader objConnection=new OleDbConnection(Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(strDb)) objCommand=new OleDbCommand("这里是SQL语句" , objConnection) objConnection.Open() objDataReader=objCommand.ExecuteReader() if objDataReader.Read() oicq.Text=Convert.ToString(objDataReader["useroicq"]) homesite.Text=Convert.ToString(objDataReader["usersite"]) face.SelectedItem.Text=Convert.ToString(objDataReader["userface"]) end if 其实大家比较一下C#和VB的语法,会发觉用C#似乎更加简单,教程里面我侧重C#,对于VB的代码我就不解释了。 下面说一下如果代码是读取SQL数据库,我们这样来转变 1、把代码开始的 <%@Import Namespace="System.Data"%> <%@Import Namespace="System.Data.OleDb"%> 修改为 <%@Import Namespace="System.Data"%> <%@Import Namespace="System.Data.SqlClient"%> 2、把代码里面所有申明的对象OleDb××变为Sql××就这么简单 你甚至可以用替换所有来解决,所以今后我讲不再列出Sql Server的代码了。 今天就说到这里,明天开始说数据的添加、删除、修改。 十天学会ASP.net(7) 作者:佚名 阅读人次:6818 文章来源:未知 发布时间:2005-6-24 网友评论(4)条 第七天 学习目的:学会添加删除修改记录 以前我们在ASP不管是添加还是删除记录或者用SQL语句加上EXECUTE()或者就是直接用RECORDSET的NEW、DELETE、UPDATE等方法来添加删除修改记录。在ASP.NET里面我们采用SQL语句加上COMMAND对象来执行SQL语句的方法来添加删除修改记录。这比上次说的读取记录还简单。实际上只有一点区别,把ExecuteReader()修改为ExecuteNonQuery()即可,因为我们不需要返回值啊。 string strConnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source="; strConnection+=Server.MapPath(strDb); OleDbConnection objConnection=new OleDbConnection(strConnection); OleDbCommand objCommand = new OleDbCommand("这里是SQL语句" , objConnection); objConnection.Open(); OleDbDataReader objDataReader=objCommand.ExecuteNonQuery(); ________________________________________ dim objConnection as OleDbConnection dim objCommand as OleDbCommand objConnection=new OleDbConnection(Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath(strDb)) objCommand=new OleDbCommand("这里是SQL语句" , objConnection) objConnection.Open() objDataReader=objCommand.ExecuteNoQuery() 下面再举例子说明一下SQL语句(ACCESS): 添加记录: insert int o 表名 (字段1,字段2) values (字符串1,字符串2) where 条件 删除记录: delete from 表名 where 条件 修改记录: update 表名 set 字段1=××,字段2=×× where 条件 需要特别注意,如果是Sql Server删除记录是delete 表名,不需要再加from了。 今天就说到这里了,明天说ASP.NET里面最著名的DATAGRID。 十天学会ASP.net(8) 作者:佚名 阅读人次:6674 文章来源:未知 发布时间:2005-6-24 网友评论(7)条 第八天 学习目的:初步掌握DATAGRID的使用 以前在ASP,我们显示大批量数据经常使用循环读取记录集的方式,在表格插入代码来显示,循环的是,如果是分页还需要自己制作,如果排序更加复杂,在ASP.NET就好了,一切工作都可以让DATAGRID来做。 首先看一下DATAGRID的样式方面的属性 BackImageUrl="" 背景图片 CellSpacing="" 单元格间距 CellPadding="" 单元格填充 cssClass="" 使用的CSS样式 DATAGRID可以自动用表的字段名放在显示的记录的头部来表示各个单元格所代表的意义,用ShowHeader="true/false"来制是不是显示,在大多数情况下我们是不需要这个功能的,因为我们数据库的字段名大多是英文的,而我们想在页面输出的大多是文名字。 下面看一下显示数据库内所有记录,就几行代码: <script runat="server" language="c#"> void Page_Load() { string strConnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source="; strConnection+=Server.MapPath("guestbook.mdb"); OleDbConnection objConnection=new OleDbConnection(strConnection); OleDbCommand objCommand1 = new OleDbCommand("select * from guestbook",objConnection); objConnection.Open(); dgrdMain.DataSource=objCommand1.ExecuteReader();//dgrdMain就是下面的DATAGRID的ID dgrdMain.DataBind(); objConnection.Close(); } 至于VB的版本,这次大家自己来试试吧:) 假设数据库是三个字段:id,aa,bb 显示的样子就如下: id aa bb 1 werwe rewrwe 2 werwe rewrwe 我们一定觉得这种显示不满意,我们有两种显示的方式(需要包括在间): 一、默认的列,我们可以选择不输出所有的字段还可以安排顺序: 比如说我们想按照bb,aa来输出这个表,我们这么写 注意使用了autogeneratecolumns="false"以后DATAGRID就不会自动输出所有字段了。 二、以模板列,我们可以定制每一个单元格的样式: 间是一个表格,想怎么样就怎么样 或许你们要说怎么在表格输出代码那,可以使用<%# DataBinder.Eval(Container.DataItem,"字段名").ToString()%> 下面看一个例子,我们所要做的就是把aa,bb两个字段放在一个单元格内显示,就好像下面一样: 1 werwe rewrwe 2 werwe rewrwe 我们这样写代码: 首先使用默认的显示方式显示ID 使用模板来显示后面一列(由AA,BB并列组成)
<%# Container.DataItem("aa")%>
<%# Container.DataItem("bb")%>
今天就说到这里,明天我们来看一下DATAGRID的分页显示等功能 十天学会ASP.net(9) 作者:佚名 阅读人次:5514 文章来源:未知 发布时间:2005-6-24 网友评论(7)条 第九天 学习目的:学会用DATAGRID分页显示 虽然说DATAGRID的分页显示效率不怎么高,但是不管怎么说,它是最方便的分页显示,对于做一个留言簿还是相当简单实用的。对于启用分页功能还有一个重要要求,只能在DATADRID件的数据源实现了ICOLLECTION接口的情况下才能启用分页功能,而DATAREADER没有这个接口,所以必须使用DATATABLE来代替。 <script runat="server" language="c#"> void Page_Load() { string strConnection="Provider=Microsoft.Jet.OleDb.4.0;Data Source="; strConnection+=Server.MapPath("guestbook.mdb"); OleDbConnection objConnection=new OleDbConnection(strConnection); OleDbDataAdapter objDataAdapter=new OleDbDataAdapter("select * from guestbook",objConnection); DataSet objDataSet=new DataSet(); objDataAdapter.Fill(objDataSet); dgrdMain.DataSource=objDataSet; dgrdMain.DataBind(); } void dgrdMain_PageIndexChanged(Object sender, DataGridPageChangedEventArgs e) { dgrdMain.CurrentPageIndex = e.NewPageIndex; DataBind(); } ________________________________________ <script runat="server" language="vb"> subPage_Load dim objConnection as OleDbConnection dim objDataAdapter as OleDbDataAdapter dim objDataSet as DataSet objConnection=new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("guestbook.mdb")) objDataAdapter=new OleDbDataAdapter("select * from guestbook",objConnection) objDataSet=new DataSet objDataAdapter.Fill(objDataSet) dgrdMain.DataSource=objDataSet dgrdMain.DataBind() end sub sub dgrdMain_PageIndexChanged(sender as object,e as datagridpagechangedeventargs) dgrdMain.CurrentPageIndex = e.NewPageIndex DataBind end sub 这样就是最简单的分页,我们可以用参数pagestyle-mode="nextprev/numericpages"来设定是显示上一页、下一页方式还是直接选择页面的数字方式来实现页面跳转。如果是前者我们可以用pagestyle-nextpagetext来设定包含下一页链接的文本,用pagestyle-prevpagetext来设定包含上一页链接的文本;如果是后者我们可以用PagerStyle-PageButtonCount来设定在使用省略号之前显示的页面编号数量(默认是10) 今天就说到这里,明天说一下SESSION和COOKIE。 十天学会ASP.net(10) 作者:佚名 阅读人次:5305 文章来源:未知 发布时间:2005-6-24 网友评论(8)条 第十天 学习目的:学会SESSION和COOKIE的使用 在各个网页间的变量传递和一些记录用户的登陆信息要用到SESSION和COOKIE。在ASP.NET使用COOKIE比ASP稍微麻烦一点,因为我们要申明变量。 首先看一下SESSION的使用,基本和ASP差不多 写入一个SESSION: Session["username"])="aa"; ________________________________________ Session("username")="aa" 读取一个SESSINN: string username= Session["username"]; ________________________________________ dim username=Session("username") 再来看一下COOKIE的写入: DateTime dt=DateTime.Now; //需要<%@Import Namespace="System"%>,得到当前时间 HttpCookie mycookie=new HttpCookie("logname");//申明新的COOKIE变量 mycookie.Value="aa";//赋值 mycookie.Expires=Convert.ToDateTime(dt+TimeSpan.FromDays(1));//设定过期时间为1天 Response.Cookies.Add(mycookie1);//写入COOKIE ________________________________________ dim dt as DateTime dt=DataTime.Now dim mycookie as HttpCookie mycookie=new HttpCookie("logname") mycookie.Value="aa" mycookie.Expires=Convert.ToDateTime(dt+TimeSpan.FromDays(1)) Response.Cookies.Add(mycookie1) 看一下COOKIE的读取: HttpCookie mycookie=Request.Cookies["username"]; string username=mycookie.Value; ________________________________________ dim mycookie as HttpCookie mycookie=Request.Cookies["username"] dim string=mycookie.Value 到此《十天学会ASP.NET》结束了

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧