- ·上一篇文章:用Visual C#获得计算机名称和IP地址
- ·下一篇文章:用C#写计算器程序(二)
用Visual C#中轻松浏览数据库记录
em.Drawing.Size(40, 24) ;
previousrec.TabIndex = 6 ;
previousrec.Font = new System.Drawing.Font ( "仿宋" , 8f ) ;
previousrec.Text = "上一条" ;
previousrec.Click += new System.EventHandler ( GoPrevious ) ;
nextrec.Location = new System.Drawing.Point ( 195 , 312 );
nextrec.ForeColor = System.Drawing.Color.Black ;
nextrec.Size = new System.Drawing.Size ( 40 , 24 ) ;
nextrec.TabIndex = 7 ;
nextrec.Font = new System.Drawing.Font ( "仿宋" , 8f ) ;
nextrec.Text = "下一条" ;
nextrec.Click += new System.EventHandler ( GoNext );
lastrec.Location = new System.Drawing.Point ( 265 , 312 ) ;
lastrec.ForeColor = System.Drawing.Color.Black ;
lastrec.Size = new System.Drawing.Size ( 40 , 24 ) ;
lastrec.TabIndex = 8 ;
lastrec.Font = new System.Drawing.Font ( "仿宋" , 8f ) ;
lastrec.Text = "尾记录" ;
lastrec.Click += new System.EventHandler ( GoLast ) ;
//以下是对为显示数据记录而设定的标签和文本框进行初始化,并把记录绑定在不同的绑定到文本框"Text"属性上
t_bookid.Location = new System.Drawing.Point ( 184 , 56 ) ;
t_bookid.TabIndex = 9 ;
t_bookid.Size = new System.Drawing.Size ( 80 , 20 ) ;
t_bookid.DataBindings.Add ( "Text" , myDataSet , "books.bookid" ) ;
t_books.Location = new System.Drawing.Point ( 184 , 264 ) ;
t_books.TabIndex = 10 ;
t_books.Size = new System.Drawing.Size ( 80 , 20 ) ;
t_books.DataBindings.Add ( "Text" , myDataSet , "books.bookstock" ) ;
t_booktitle.Location = new System.Drawing.Point ( 184 , 108 ) ;
t_booktitle.TabIndex = 11 ;
t_booktitle.Size = new System.Drawing.Size ( 176 , 20 ) ;
t_booktitle.DataBindings.Add( "Text" , myDataSet , "books.booktitle" ) ;
t_bookprice.Location = new System.Drawing.Point ( 184 , 212 ) ;
t_bookprice.TabIndex = 12 ;
t_bookprice.Size = new System.Drawing.Size ( 80 , 20 ) ;
t_bookprice.DataBindings.Add ( "Text" , myDataSet , "books.bookprice" ) ;
t_bookauthor.Location = new System.Drawing.Point ( 184 , 160 ) ;
t_bookauthor.TabIndex = 18 ;
t_bookauthor.Size = new System.Drawing.Size ( 128 , 20 ) ;
t_bookauthor.DataBindings.Add ( "Text" , myDataSet , "books.bookauthor" ) ;
l_bookid.Location = new System.Drawing.Point ( 24 , 56 ) ;
l_bookid.Text = "书本序号:" ;
l_bookid.Size = new System.Drawing.Size ( 112, 20 ) ;
l_bookid.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;
l_bookid.TabIndex = 13 ;
l_bookid.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_booktitle.Location = new System.Drawing.Point ( 24 , 108 ) ;
l_booktitle.Text = "书 名:";
l_booktitle.Size = new System.Drawing.Size ( 112 , 20 ) ;
l_booktitle.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;
l_booktitle.TabIndex = 14 ;
l_booktitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_bookprice.Location = new System.Drawing.Point ( 24 , 212 ) ;
l_bookprice.Text = "价 格:" ;
l_bookprice.Size = new System.Drawing.Size ( 112 , 20 ) ;
l_bookprice.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;
l_bookprice.TabIndex = 15 ;
l_bookprice.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_books.Location = new System.Drawing.Point ( 24 , 264 ) ;
l_books.Text = "书 架 号:" ;
l_books.Size = new System.Drawing.Size ( 112 , 20 ) ;
l_books.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;
l_books.TabIndex = 16 ;
l_books.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_bookauthor.Location = new System.Drawing.Point ( 24 , 160 ) ;
l_bookauthor.Text = "作 者:" ;
l_bookauthor.Size = new System.Drawing.Size ( 112 , 20 ) ;
l_bookauthor.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;
l_bookauthor.TabIndex = 17 ;
l_bookauthor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
label1.Location = new System.Drawing.Point ( 49 , 8 ) ;
label1.Text = "浏览书籍信息" ;
label1.Size = new System.Drawing.Size ( 296 , 24 ) ;
label1.ForeColor = System.Drawing.Color.Green ;
label1.Font = new System.Drawing.Font ( "仿宋" , 15f ) ;
label1.TabIndex = 19 ;
//对窗体进行设定
this.Text = "用C#做浏览数据库中记录的程序!";
this.AutoScaleBaseSize = new System.Drawing.Size ( 5 , 13 ) ;
this.FormBorderStyle = FormBorderStyle.FixedSingle ;
this.ClientSize = new System.Drawing.Size ( 394 , 375 ) ;
//在窗体中加入组件
this.Controls.Add ( lastrec ) ;
this.Controls.Add ( nextrec ) ;
this.Controls.Add ( previousrec ) ;
this.Controls.Add ( firstrec ) ;
this.Controls.Add ( t_books ) ;
this.Controls.Add ( t_bookprice ) ;
this.Controls.Add ( t_bookauthor ) ;
this.Controls.Add ( t_booktitle ) ;
this.Controls.Add ( t_bookid ) ;
this.Controls.Add ( l_books ) ;
this.Controls.Add ( l_bookprice ) ;
this.Controls.Add ( l_bookauthor ) ;
this.Controls.Add ( l_booktitle ) ;
this.Controls.Add ( l_bookid ) ;
this.Controls.Add ( label1 ) ;
//把对象DataSet和"books"数据表绑定到此myBind对象
myBind= this.BindingContext [ myDataSet , "books" ] ;
}
//按钮"尾记录"对象事件程序
protected void GoLast ( object sender , System.EventArgs e )
{
myBind.Position = myBind.Count - 1 ;
}
//按钮"下一条"对象事件程序
protected void GoNext ( object sender , System.EventArgs e )
{
if ( myBind.Position == myBind.Count -1 )
MessageBox.Show ( "已经到了最后
previousrec.TabIndex = 6 ;
previousrec.Font = new System.Drawing.Font ( "仿宋" , 8f ) ;
previousrec.Text = "上一条" ;
previousrec.Click += new System.EventHandler ( GoPrevious ) ;
nextrec.Location = new System.Drawing.Point ( 195 , 312 );
nextrec.ForeColor = System.Drawing.Color.Black ;
nextrec.Size = new System.Drawing.Size ( 40 , 24 ) ;
nextrec.TabIndex = 7 ;
nextrec.Font = new System.Drawing.Font ( "仿宋" , 8f ) ;
nextrec.Text = "下一条" ;
nextrec.Click += new System.EventHandler ( GoNext );
lastrec.Location = new System.Drawing.Point ( 265 , 312 ) ;
lastrec.ForeColor = System.Drawing.Color.Black ;
lastrec.Size = new System.Drawing.Size ( 40 , 24 ) ;
lastrec.TabIndex = 8 ;
lastrec.Font = new System.Drawing.Font ( "仿宋" , 8f ) ;
lastrec.Text = "尾记录" ;
lastrec.Click += new System.EventHandler ( GoLast ) ;
//以下是对为显示数据记录而设定的标签和文本框进行初始化,并把记录绑定在不同的绑定到文本框"Text"属性上
t_bookid.Location = new System.Drawing.Point ( 184 , 56 ) ;
t_bookid.TabIndex = 9 ;
t_bookid.Size = new System.Drawing.Size ( 80 , 20 ) ;
t_bookid.DataBindings.Add ( "Text" , myDataSet , "books.bookid" ) ;
t_books.Location = new System.Drawing.Point ( 184 , 264 ) ;
t_books.TabIndex = 10 ;
t_books.Size = new System.Drawing.Size ( 80 , 20 ) ;
t_books.DataBindings.Add ( "Text" , myDataSet , "books.bookstock" ) ;
t_booktitle.Location = new System.Drawing.Point ( 184 , 108 ) ;
t_booktitle.TabIndex = 11 ;
t_booktitle.Size = new System.Drawing.Size ( 176 , 20 ) ;
t_booktitle.DataBindings.Add( "Text" , myDataSet , "books.booktitle" ) ;
t_bookprice.Location = new System.Drawing.Point ( 184 , 212 ) ;
t_bookprice.TabIndex = 12 ;
t_bookprice.Size = new System.Drawing.Size ( 80 , 20 ) ;
t_bookprice.DataBindings.Add ( "Text" , myDataSet , "books.bookprice" ) ;
t_bookauthor.Location = new System.Drawing.Point ( 184 , 160 ) ;
t_bookauthor.TabIndex = 18 ;
t_bookauthor.Size = new System.Drawing.Size ( 128 , 20 ) ;
t_bookauthor.DataBindings.Add ( "Text" , myDataSet , "books.bookauthor" ) ;
l_bookid.Location = new System.Drawing.Point ( 24 , 56 ) ;
l_bookid.Text = "书本序号:" ;
l_bookid.Size = new System.Drawing.Size ( 112, 20 ) ;
l_bookid.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;
l_bookid.TabIndex = 13 ;
l_bookid.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_booktitle.Location = new System.Drawing.Point ( 24 , 108 ) ;
l_booktitle.Text = "书 名:";
l_booktitle.Size = new System.Drawing.Size ( 112 , 20 ) ;
l_booktitle.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;
l_booktitle.TabIndex = 14 ;
l_booktitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_bookprice.Location = new System.Drawing.Point ( 24 , 212 ) ;
l_bookprice.Text = "价 格:" ;
l_bookprice.Size = new System.Drawing.Size ( 112 , 20 ) ;
l_bookprice.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;
l_bookprice.TabIndex = 15 ;
l_bookprice.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_books.Location = new System.Drawing.Point ( 24 , 264 ) ;
l_books.Text = "书 架 号:" ;
l_books.Size = new System.Drawing.Size ( 112 , 20 ) ;
l_books.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;
l_books.TabIndex = 16 ;
l_books.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
l_bookauthor.Location = new System.Drawing.Point ( 24 , 160 ) ;
l_bookauthor.Text = "作 者:" ;
l_bookauthor.Size = new System.Drawing.Size ( 112 , 20 ) ;
l_bookauthor.Font = new System.Drawing.Font ( "仿宋" , 10f ) ;
l_bookauthor.TabIndex = 17 ;
l_bookauthor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter ;
label1.Location = new System.Drawing.Point ( 49 , 8 ) ;
label1.Text = "浏览书籍信息" ;
label1.Size = new System.Drawing.Size ( 296 , 24 ) ;
label1.ForeColor = System.Drawing.Color.Green ;
label1.Font = new System.Drawing.Font ( "仿宋" , 15f ) ;
label1.TabIndex = 19 ;
//对窗体进行设定
this.Text = "用C#做浏览数据库中记录的程序!";
this.AutoScaleBaseSize = new System.Drawing.Size ( 5 , 13 ) ;
this.FormBorderStyle = FormBorderStyle.FixedSingle ;
this.ClientSize = new System.Drawing.Size ( 394 , 375 ) ;
//在窗体中加入组件
this.Controls.Add ( lastrec ) ;
this.Controls.Add ( nextrec ) ;
this.Controls.Add ( previousrec ) ;
this.Controls.Add ( firstrec ) ;
this.Controls.Add ( t_books ) ;
this.Controls.Add ( t_bookprice ) ;
this.Controls.Add ( t_bookauthor ) ;
this.Controls.Add ( t_booktitle ) ;
this.Controls.Add ( t_bookid ) ;
this.Controls.Add ( l_books ) ;
this.Controls.Add ( l_bookprice ) ;
this.Controls.Add ( l_bookauthor ) ;
this.Controls.Add ( l_booktitle ) ;
this.Controls.Add ( l_bookid ) ;
this.Controls.Add ( label1 ) ;
//把对象DataSet和"books"数据表绑定到此myBind对象
myBind= this.BindingContext [ myDataSet , "books" ] ;
}
//按钮"尾记录"对象事件程序
protected void GoLast ( object sender , System.EventArgs e )
{
myBind.Position = myBind.Count - 1 ;
}
//按钮"下一条"对象事件程序
protected void GoNext ( object sender , System.EventArgs e )
{
if ( myBind.Position == myBind.Count -1 )
MessageBox.Show ( "已经到了最后
