简单ACCESS处理问题
错误报告为:至少一个参数没有被指定值
//以下是源代码
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace myApp
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtcomment;
private System.Windows.Forms.TextBox txtclass;
private System.Windows.Forms.TextBox txtname;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
//数据连接
private void GetConnect(string strSql)
{
string strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+Application.StartupPath+@"\mydb.mdb";
OleDbConnection myConn=new OleDbConnection(strConn);
myConn.Open();
OleDbCommand myCommand=new OleDbCommand(strSql,myConn);
myCommand.ExecuteNonQuery();
myConn.Close();
}
private void Run()
{
if(txtname.Text!="")
{
if(txtclass.Text!="")
{
string strSql="INSERT INTO base (proname,proclass,comment) VALUES ("+txtname.Text+","+txtclass.Text+","+txtcomment.Text+")";
GetConnect(strSql);
txtname.Clear();
txtclass.Clear();
txtcomment.Clear();
}
else
{
MessageBox.Show("请您输入产品阻值类别","错误");
}
}
else
{
MessageBox.Show("请您输入产品名字","错误");
}
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.txtcomment = new System.Windows.Forms.TextBox();
this.txtclass = new System.Windows.Forms.TextBox();
this.txtname = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button2,
this.button1,
this.txtcomment,
this.txtclass,
this.txtname,
this.label3,
this.label2,
this.label1});
this.groupBox1.Location = new System.Drawing.Point(0, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(320, 256);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
//
// button2
//
this.button2.Location = new System.Drawing.Point(232, 221);
this.button2.Name = "button2";
this.button2.TabIndex = 15;
this.button2.Text = "退出(&X)";
//
// button1
//
this.button1.Location = new System.Drawing.Point(119, 221);
this.button1.Name = "button1";
this.button1.TabIndex = 14;
this.button1.Text = "保存(&S)";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// txtcomment
//
this.txtcomment.Location = new System.Drawing.Point(103, 117);
this.txtcomment.Multiline = true;
this.txtcomment.Name = "txtcomment";
this.txtcomment.ScrollBars = System.Windows.Forms.ScrollBars.Horizontal;
this.txtcomment.Size = new System.Drawing.Size(208, 80);
this.txtcomment.TabIndex = 13;
this.txtcomment.Text = "";
//
// txtclass
//
this.txtclass.Location = new System.Drawing.Point(103, 61);
this.txtclass.Name = "txtclass";
this.txtclass.Size = new System.Drawing.Size(208, 21);
this.txtclass.TabIndex = 12;
this.txtclass.Text = "";
//
// txtname
//
this.txtname.Location = new System.Drawing.Point(103, 13);
this.txtname.Name = "txtname";
this.txtname.Size = new System.Drawing.Size(208, 21);
this.txtname.TabIndex = 11;
this.txtname.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(7, 125);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(64, 24);
this.label3.TabIndex = 10;
this.label3.Text = "说明备注";
//
// label2
//
this.label2.Location = new System.Drawing.Point(7, 69);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 24);
this.label2.TabIndex = 9;
this.label2.Text = "阻值类别";
//
// label1
//
this.label1.Location = new System.Drawing.Point(7, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 24);
this.label1.TabIndex = 8;
this.label1.Text = "产品名称";
//
// Form3
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(320, 263);
this.ControlBox = false;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.groupBox1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MinimizeBox = false;
this.Name = "Form3";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "基础数据录入";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
Run();
}
}
}
谢谢各位了:
我在另外一个地方用:
string myStr="select username,userpass from user where username="+inputName.Text;
也出现了:至少有一个参数没有被指定值
我换成了
string myStr="select username,userpass from user";
就没有错误报告。