using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace bookever
{
public partial class Form2 : Form
{
private OleDbConnection oc;
private OleDbDataAdapter da;
private OleDbCommand cm;
private DataSet ds;
public Form2(int i)
{
InitializeComponent();
oc = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data source=F:\book\Book.mdb");
da = new OleDbDataAdapter("select * from Book", oc);
ds = new DataSet();
da.Fill(ds, "emp");
this.txtname.Text = ds.Tables[0].Rows[i]["BookName"].ToString();
this.txtisbn.Text = ds.Tables[0].Rows[i]["Isbn"].ToString();
this.txtauthor.Text = ds.Tables[0].Rows[i]["Author"].ToString();
this.txtpublisher.Text = ds.Tables[0].Rows[i]["Publisher"].ToString();
this.txtprice.Text = ds.Tables[0].Rows[i]["Price"].ToString();
if (ds.Tables[0].Rows[i]["Borrower"] != null)
{
MessageBox.Show("你可以借阅这本书");
label6.Text = "借阅者";
}
else
{
MessageBox.Show("你是否还书");
label6.Text = "还书者";
}
}
private void Form2_Load(object sender, EventArgs e)
{
oc = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data source=F:\book\Book.mdb");
da = new OleDbDataAdapter("select * from Book", oc);
ds = new DataSet();
da.Fill(ds, "emp");
}
private void btnYES_Click(object sender, EventArgs e)
{
string sql = "insert into Book(Borrower)";
sql += "values(@borrower)";
cm = new OleDbCommand(sql, oc);
if (label6.Text == "借阅者")
{
cm.Parameters.Add("@borrower", OleDbType.VarChar, 50).Value = this.txtborrower.Text;
}
else if (label6.Text == "还书者")
{
cm.Parameters.Remove(this.txtborrower.Text);
}
else
{
MessageBox.Show("您输入有误!");
}
try
{
oc.Open();
cm.ExecuteNonQuery();
MessageBox.Show("操作成功");
}
catch
{
MessageBox.Show("操作失败");
}
finally
{
oc.Close();
}
}
}
}
没报什么错误!怎么添加不进去呢1请指点下1