| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 479 人关注过本帖
标题:[求助]怎么插不进去数据
只看楼主 加入收藏
学技术
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2006-9-19
收藏
 问题点数:0 回复次数:2 
[求助]怎么插不进去数据

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

搜索更多相关主题的帖子: using System 数据 private public 
2006-10-13 03:18
hoya
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:538
专家分:0
注 册:2006-6-27
收藏
得分:0 
string sql = "insert into Book(Borrower)";
sql += "values(@borrower)";


sql 语句有问题... 检查看看....

妈的...一天能卖一颗就很不错了...
2006-10-13 08:44
学技术
Rank: 1
等 级:新手上路
帖 子:27
专家分:0
注 册:2006-9-19
收藏
得分:0 

哦!谢谢!可是还是不行哦!
我把数据库改了下行!但是我刚开始设计的是非空!改成空的就可以插进去!
忽忽!
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();
}
这个就能插进 去!
可下面那个不行哦!

2006-10-20 01:14
快速回复:[求助]怎么插不进去数据
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014504 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved