c#数据库,图书查询系统,求指导答出现的几个问题

.Net技术 码拜 4年前 (2016-02-26) 307次浏览
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data;
public  class DataView : Form
{
private System.ComponentModel.Container components;
private Button lastrec;
private Button nextrec;
private Button previousrec;
private Button firstrec;
private TextBox t_books;
private TextBox t_bookprice;
private TextBox t_bookauthor;
private TextBox t_booktitle;
private TextBox t_bookid;
private Label l_books;
private Label l_bookprice;
private Label l_bookauthor;
private Label l_booktitle;
private Label l_bookid;
private Label label1;
private GroupBox GroupBox1;
private StatusBar statusbar;
private System.Data.DataSet myDataSet;
private BindingManagerBase myBind;
public DataView()
{
GetConnected();
InitializeComponent();
}
protected override void Dispose()
{
base.Dispose();
components.Dispose();
}
public static void Main()
{
Application.Run(new DataView());
}
public void GetConnected()
{
try
{
string strCon = ” Provider =Microsoft.Jet.OLEDB.4.0; Data Source = d:\book2.mdb”;
OleDbConnection myConn = new OleDbConnection(strCon);
string strCom = ” SELECT * FROM bookstock”;
myDataSet = new DataSet();
myConn.Open();
OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn);
myCommand.Fill(myDataSet, “bookstock”);
myConn.Close();
}
catch (Exception e)
{
MessageBox.Show(” 连接错误! ” + e.ToString(), “错误”);
}
}
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.nextrec = new Button();
this.lastrec = new Button();
this.l_bookid = new Label();
this.t_bookid = new TextBox();
this.t_books = new TextBox();
this.t_bookprice = new TextBox();
this.t_booktitle = new TextBox();
this.firstrec = new Button();
this.l_booktitle = new Label();
this.l_bookprice = new Label();
this.l_books = new Label();
this.previousrec = new Button();
this.l_bookauthor = new Label();
this.t_bookauthor = new TextBox();
this.label1 = new Label();
GroupBox1 = new GroupBox();
this.statusbar = new StatusBar();
firstrec.Location = new System.Drawing.Point(55, 312);
firstrec.ForeColor = System.Drawing.Color.Black;
firstrec.Size = new System.Drawing.Size(40, 24);
firstrec.TabIndex = 5;
firstrec.Text = “首记录”;
firstrec.Click += new System.EventHandler(GoFirst);
previousrec.Location = new System.Drawing.Point(125, 312);
previousrec.ForeColor = System.Drawing.Color.Black;
previousrec.Size = new System.Drawing.Size(40, 24);
previousrec.TabIndex = 6;
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.Text = “下一条”;
nextrec.Click += new System.EventHandler(GoNext);
lastrec.Location = new System.Drawing.Point(265, 312);
lastrec.Size = new System.Drawing.Size(40, 24);
lastrec.ForeColor = System.Drawing.Color.Black;
lastrec.TabIndex = 8;
lastrec.Text = “尾记录”;
lastrec.Click += new System.EventHandler(GoLast);
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, “bookstock.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, “bookstock.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, “bookstock.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, “bookstock.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, “bookstock.bookauthor”);
l_bookid.Location = new System.Drawing.Point(24, 56);
l_bookid.Text = “书本序号:”;
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.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.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.TabIndex = 16;
l_books.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
l_bookauthor.Location = new System.Drawing.Point(24, 160);
l_bookauthor.Text = “作者:”;
l_bookauthor.TabIndex = 17;
l_bookauthor.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
label1.Location = new System.Drawing.Point(49, 8);
label1.Text = “浏览书籍信息”;
label1.TabIndex = 19;
GroupBox1.Location = new System.Drawing.Point(10, 30);
GroupBox1.Size = new System.Drawing.Size(296, 24);
GroupBox1.TabIndex = 20;
statusbar.BackColor = System.Drawing.SystemColors.Control;
statusbar.Location = new System.Drawing.Point(0, 401);
statusbar.Text = “Ready!”;
this.Text = “书籍浏览系统”;
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);
this.Controls.Add(GroupBox1);
this.Controls.Add(statusbar);
myBind = this.BindingContext[myDataSet, “bookstock”];
}
protected void GoFirst(object sender, System.EventArgs e)
{
myBind.Position = 0;
lastrec.Enabled = (myBind.Position == 0);
nextrec.Enabled = (myBind.Position == 0);
previousrec.Enabled = !(myBind.Position == 0);
statusbar.Text = “第” + (myBind.Position + 1).ToString() + “条数据”;
}
protected void GoPrevious(object sender, System.EventArgs e)
{
lastrec.Enabled = true;
nextrec.Enabled = true;
previousrec.Enabled = !(myBind.Position == 0);
firstrec.Enabled = !(myBind.Position == 0);
if (myBind.Position == 0)
{
statusbar.Text = “已经到了第一条记录!”;
}
else
{
myBind.Position -= 1;
statusbar.Text = “第” + (myBind.Position + 1).ToString() + “条数据”;
}
}
protected void GoNext(object sender, System.EventArgs e)
{
lastrec.Enabled = !(myBind.Position == myBind.Count – 1);
nextrec.Enabled = !(myBind.Position == myBind.Count – 1);
previousrec.Enabled = true;
firstrec.Enabled = true;
if (myBind.Position == myBind.Count – 1)
{
statusbar.Text = “第” + (myBind.Position + 1).ToString() + “条数据.” + “已经到了最后一条记录!”;
}
else
{
myBind.Position += 1;
statusbar.Text = “第” + (myBind.Position + 1).ToString() + “条数据”;
}
}
protected void GoLast(object sender, System.EventArgs e)
{
myBind.Position = myBind.Count – 1;
lastrec.Enabled = !(myBind.Position == myBind.Count – 1);
nextrec.Enabled = !(myBind.Position == myBind.Count – 1);
previousrec.Enabled = (myBind.Position == myBind.Count – 1);
firstrec.Enabled = (myBind.Position == myBind.Count – 1);
statusbar.Text = “第” + (myBind.Position + 1).ToString() + “条数据”;
}
}
错误 1 程序“D:\大作业\WindowsFormsApplication4\WindowsFormsApplication4\obj\x86\Debug\WindowsFormsApplication4.exe”定义了不止一个入口点:“WindowsFormsApplication4.Program.Main()”。请使用 /main 进行编译,以指定包含入口点的类型。 14 21 WindowsFormsApplication4
错误 2 “WindowsFormsApplication4.DataView.Dispose(bool)”: 没有找到适合的方法来重写 14 33 WindowsFormsApplication4
错误 3 “DataView.Dispose()”: 当重写“public”继承成员“System.ComponentModel.Component.Dispose()”时,无法更改访问修饰符 36 29 WindowsFormsApplication4
错误 4 “DataView.Dispose()”: 继承成员“System.ComponentModel.Component.Dispose()”未标记为 virtual、abstract 或 override,无法进行重写 36 29 WindowsFormsApplication4
解决方案

40

Main方法只能有一个,你定义了多个Main方法,所以程序出错,不知道从哪里启动。

40

引用 2 楼 scqcainiao 的回复:

该怎么改呢?

你看看解决方案管理器里,是不是有个 Program.cs
那个文件里面应该有个 Main
然后呢,回到上面的代码文件 Ctrl+F 找到
public static void Main()
{
Application.Run(new DataView());
}
DELETE


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明c#数据库,图书查询系统,求指导答出现的几个问题
喜欢 (0)
[1034331897@qq.com]
分享 (0)