没有给出一个或多个必需参数的值当给出所有参数时 [英] No value given for one or more required parameters When all parameters are given

查看:175
本文介绍了没有给出一个或多个必需参数的值当给出所有参数时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的错误是 System.Data.dll中发生了类型为'System.Data.OleDb.OleDbException'的未处理异常

The Error i get is An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll

其他信息:没有为一个或多个必需参数提供值.

Additional information: No value given for one or more required parameters.

但这是当所有参数都出现在下面的代码时:

but this is when all parameters a present code bellow:

private OleDbDataReader dbReader;// Data Reader object
    string sConnection = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=ICTSchool.accdb";
    string sql;
    OleDbConnection dbConn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=ICTSchool.accdb");
    OleDbCommand dbCommand;

public class ComboboxItem
    {
        public string Text { get; set; }
        public object Value { get; set; }

        public override string ToString()
        {
            return Text;
        }
    } 

private void bAdd_Click(object sender, EventArgs e)
    {
        {
            dbConn = new OleDbConnection(sConnection);

            dbConn.ConnectionString = sConnection;


            dbConn.Open();
            string code = (cBQualification.SelectedItem as ComboboxItem).Value.ToString();
            string sqlinsert = "INSERT INTO Student VALUES (" + tBStudentNum.Text + "," + tBStudentName.Text+","+ tBCellNo.Text+","+ code + ")";
            Console.WriteLine("Test 'sqlinsert' "+ sqlinsert);

            dbCommand = new OleDbCommand(sqlinsert, dbConn);

            dbCommand.ExecuteNonQuery();
        }
    }

推荐答案

此处是有关如何在MS Access中插入值的文章的一部分. 要将一条记录添加到表中,必须使用字段列表来定义要在其中放入数据的字段,然后必须在值列表中提供数据本身.要定义值列表,请使用VALUES子句.

Here is part of the article about how to insert values in MS Access. To add one record to a table, you must use the field list to define which fields to put the data in, and then you must supply the data itself in a value list. To define the value list, use the VALUES clause.

例如,以下语句将分别在客户ID",姓氏"和名字"字段中插入值"1","Kelly"和"Jill".

For example, the following statement will insert the values "1", "Kelly", and "Jill" into the CustomerID, Last Name, and First Name fields, respectively.

插入tblCustomers(客户ID,[姓氏],[名字]) 值(1,凯利",吉尔")

INSERT INTO tblCustomers (CustomerID, [Last Name], [First Name]) VALUES (1, 'Kelly', 'Jill')

您可以省略字段列表,但前提是您提供记录中可以包含的所有值.

插入tblCustomers值(1,Kelly,"Jill","555-1040", 'someone@microsoft.com')

INSERT INTO tblCustomers VALUES (1, Kelly, 'Jill', '555-1040', 'someone@microsoft.com')

来源 MSDN如何:插入,更新,并使用Access SQL从表中删除记录

这篇关于没有给出一个或多个必需参数的值当给出所有参数时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆