OleDbParameters和参数名称 [英] OleDbParameters and Parameter Names

查看:182
本文介绍了OleDbParameters和参数名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我通过OleDb的执行SQL语句,该语句是这样的:

I have an SQL statement that I'm executing through OleDb, the statement is something like this:

INSERT INTO mytable (name, dept) VALUES (@name, @dept);

我添加参数来OleDbCommand这是这样的:

I'm adding parameters to the OleDbCommand like this:

OleDbCommand Command = new OleDbCommand();
Command.Connection = Connection;

OleDbParameter Parameter1 = new OleDbParameter();
Parameter1.OleDbType = OleDbType.VarChar;
Parameter1.ParamterName = "@name";
Parameter1.Value = "Bob";

OleDbParameter Parameter2 = new OleDbParameter();
Parameter2.OleDbType = OleDbType.VarChar;
Parameter2.ParamterName = "@dept";
Parameter2.Value = "ADept";

Command.Parameters.Add(Parameter1);
Command.Parameters.Add(Parameter2);

我有现在的问题是,如果我添加的参数命令倒过来,然后列填充了错误的值(即名在dept列,反之亦然)

The problem I've got is, if I add the parameters to command the other way round, then the columns are populated with the wrong values (i.e. name is in the dept column and vice versa)

Command.Parameters.Add(Parameter2);
Command.Parameters.Add(Parameter1);

我的问题是,什么是的参数名称的点,如果参数值都只是插入到表中它们被添加的命令的顺序?参数名称似乎是多余的?

My question is, what is the point of the parameter names if parameters values are just inserted into the table in the order they are added command? The parameter names seems redundant?

任何帮助apprreciated, 谢谢, 加雷思

Any help apprreciated, Thanks, Gareth

推荐答案

参数名称是通用的SQL支持系统(即不特定的OleDb)。 pretty的多只的OleDb / ODBC不使用它们。它们的存在,因为OleDb的是通用基类的一个具体的实施

Parameter NAMES are generic in the SQL support system (i.e. not OleDb specific). Pretty much ONLY OleDb / Odbc do NOT use them. They are there because OleDb is a specific implementation of the generic base classes.

这篇关于OleDbParameters和参数名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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