请教错误 :System.Data.OleDb.OleDbException 至少一个参数没有被指定值。

AkinaGTR 2017-12-04 08:05:16
KeHuShuJuBiao = new System.Data.OleDb.OleDbDataAdapter();
Ds = new DataSet();

OleDbSelectCom = new System.Data.OleDb.OleDbCommand();
OleDbInsertCom = new System.Data.OleDb.OleDbCommand();
OleDbUpdateCom = new System.Data.OleDb.OleDbCommand();
OleDbDeleteCom = new System.Data.OleDb.OleDbCommand();

KeHuShuJuBiao.DeleteCommand = OleDbDeleteCom;
KeHuShuJuBiao.InsertCommand = OleDbInsertCom;
KeHuShuJuBiao.SelectCommand = OleDbSelectCom;
KeHuShuJuBiao.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "CustomerInformationSheet", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("HomeNummber", "HomeNummber"),
new System.Data.Common.DataColumnMapping("CustomerName", "CustomerName"),
new System.Data.Common.DataColumnMapping("Sex", "Sex"),
new System.Data.Common.DataColumnMapping("IDtype", "IDtype"),
new System.Data.Common.DataColumnMapping("IDnumber", "IDnumber"),
new System.Data.Common.DataColumnMapping("Phone", "Phone"),
new System.Data.Common.DataColumnMapping("CheckInTime", "CheckInTime"),
new System.Data.Common.DataColumnMapping("CheckInDays", "CheckInDays"),
new System.Data.Common.DataColumnMapping("Deposit", "Deposit")
})
});
KeHuShuJuBiao.UpdateCommand = OleDbUpdateCom;

OleDbSelectCom.CommandText = "SELECT HomeNummber, CustomerName, Sex, IDtype,IDnumber, Phone, CheckInTime, CheckInDays, Deposit FROM CustomerInformationSheet";
OleDbSelectCom.Connection = Conn;
//
// OleDbInsertCommand1
//
OleDbInsertCom.CommandText = @"INSERT INTO CustomerInformationSheet(HomeNummber, CustomerName, Sex, IDtype,IDnumber, Phone, CheckInTime, CheckInDays,Deposit) VALUES (@HomeNummber, @CustomerName, @Sex, @IDtype, @IDnumber, @Phone, @CheckInTime, @CheckInDays, @Deposit)";
OleDbInsertCom.Connection = Conn;
OleDbInsertCom.Parameters.Add(new System.Data.OleDb.OleDbParameter("@HomeNumber", System.Data.OleDb.OleDbType.VarChar, 6, "HomeNumber"));
OleDbInsertCom.Parameters.Add(new System.Data.OleDb.OleDbParameter("@CustomerName", System.Data.OleDb.OleDbType.VarChar, 20, "CustomerName"));
OleDbInsertCom.Parameters.Add(new System.Data.OleDb.OleDbParameter("@IDtype", System.Data.OleDb.OleDbType.VarChar, 30, "IDtype"));
OleDbInsertCom.Parameters.Add(new System.Data.OleDb.OleDbParameter("@Sex", System.Data.OleDb.OleDbType.VarChar, 6, "Sex"));
OleDbInsertCom.Parameters.Add(new System.Data.OleDb.OleDbParameter("@IDnumber", System.Data.OleDb.OleDbType.Date, 8, "IDnumber"));
OleDbInsertCom.Parameters.Add(new System.Data.OleDb.OleDbParameter("@Phone", System.Data.OleDb.OleDbType.Date, 8, "Phone"));
OleDbInsertCom.Parameters.Add(new System.Data.OleDb.OleDbParameter("@CheckInTime", System.Data.OleDb.OleDbType.VarChar, 60, "CheckInTime"));
OleDbInsertCom.Parameters.Add(new System.Data.OleDb.OleDbParameter("@CheckInDays", System.Data.OleDb.OleDbType.VarChar, 10, "CheckInDays"));
OleDbInsertCom.Parameters.Add(new System.Data.OleDb.OleDbParameter("@Deposit", System.Data.OleDb.OleDbType.VarChar, 24, "Deposit"));


KeHuShuJuBiao.Fill(Ds, "CustomerInformationSheet");问题出在这句
Dt = Ds.Tables["CustomerInformationSheet"];
dataGridView1.DataSource = Dt;
dataGridView1.DataMember = "";

...全文
132 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2017-12-04
  • 打赏
  • 举报
回复
表中还有位开列的,不允许为空的字段
FainSheeg 2017-12-04
  • 打赏
  • 举报
回复
眼睛都看花了
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.OleDb; namespace 保存GRID数据示例 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button2_Click(object sender, EventArgs e) { //提示是否修改 #region//--------修改数据就将数据保存并显示 if (MessageBox.Show("是否保存数据?", "系统消息", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.OK) { #region ..........这里是保存数据代码 //结束编辑 dataGridView1.EndEdit(); //重新用表格数据填充数据容器 OleDbDataAdapter Ada = new OleDbDataAdapter(); DataTable table = (DataTable)dataGridView1.DataSource; //重新启动连接 String ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath + "/驱动.mdb"; //用Buider方法更新数据 using (OleDbConnection connection = new OleDbConnection(ConnectionString)) { Ada.SelectCommand = new OleDbCommand("SELECT * FROM 表", connection); OleDbCommandBuilder builder = new OleDbCommandBuilder(Ada); Ada.UpdateCommand = builder.GetUpdateCommand(); try { //更新数据表数据时 Ada.Update(table); table.AcceptChanges(); MessageBox.Show("操作已成功!数据将全部被保存......", "系统消息", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2); } catch (System.Data.OleDb.OleDbException ex) { throw new Exception(ex.Message); } } #endregion } #endregion #region //--------不修改就初始化显示以前数据 else { MessageBox.Show("用户取消操作,数据将恢复到初始状态......"); OleDbConnection A = new OleDbConnection(); A.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath + "/驱动.mdb"; try { A.Open(); DataSet B = new DataSet(); string sqlStr = "Select * from 表"; OleDbDataAdapter C = new OleDbDataAdapter(sqlStr, A); C.Fill(B); dataGridView1.DataSource = B.Tables[0]; } catch (System.Data.OleDb.OleDbException ex) { throw new Exception(ex.Message); } finally { A.Close(); } } #endregion } private void button1_Click(object sender, EventArgs e) { OleDbConnection A = new OleDbConnection(); A.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath + "/驱动.mdb"; try { A.Open(); DataSet B = new DataSet(); string sqlStr = "Select * from 表"; OleDbDataAdapter C = new OleDbDataAdapter(sqlStr, A); C.Fill(B); dataGridView1.DataSource = B.Tables[0]; } catch (System.Data.OleDb.OleDbException ex) { throw new Exception(ex.Message); } finally { A.Close(); } } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { } } }

110,538

社区成员

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

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

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