oledbparameter

Using Parameters with OleDbDataAdapter in C#

倖福魔咒の 提交于 2020-01-05 03:36:10
问题 I'm using OleDb to populate a DataTable. I'm trying to use a parameterized query, but it doesn't seem to work with a OleDbDataAdapter. Anyone have any suggestions? cmd.CommandText = "SELECT A,B,C,D FROM someTable WHERE A=@A AND D BETWEEN @D1 AND @D2"; cmd.Parameters.Add("@A", OleDbType.VarChar).Value = "1234567"; cmd.Parameters.Add("@D1", OleDbType.DBDate).Value = "02/01/2011"; cmd.Parameters.Add("@D2", OleDbType.DBDate).Value = "01/31/2012"; A first chance exception of type 'System.Data

Passing a DateTime value as a parameter to an OleDbCommand

余生长醉 提交于 2019-12-22 11:23:39
问题 I have a problem passing a DateTime value to a query as a DbParameter. It seems the time part of the DateTime value gets stripped away. Here is a sample code in C#: DbProviderFactory _factory = OleDbFactory.Instance; DbCommand cmd = _factory.CreateCommand(); cmd.CommandText = "INSERT INTO SomeTable (SomeDateField) VALUES (?)"; DbParameter p = _factory.CreateParameter(); p.ParameterName = ""; // Not necessary p.Value = DateTime.Now; // assume Time != 00:00:00 p.DbType = DbType.Date; //

The OleDbParameter's name obsession

人走茶凉 提交于 2019-12-14 03:50:59
问题 Since the OleDbParameter does not use named parameters (due to its nature), why is it that the .NET OleDbParameter class expects a name? (string parametername ...) All constructors require a parameter name, and I'm never sure what name to give it; my name is ok? or my grandmothers name? 回答1: Although the OleDb/Odbc providers use positional parameters instead of named parameters - the parameters will need to be identified in some way inside the OleDbParameter collection should you need to

Null Reference Exception [duplicate]

有些话、适合烂在心里 提交于 2019-12-13 03:59:37
问题 This question already has answers here : What is a NullReferenceException, and how do I fix it? (29 answers) Closed 3 years ago . This code generates and Null Reference exception. Exception comes at the line where the parameter array is initialized. What can be the problem? I don't know howto follow the stack-trace and work any logic over it. thanks in advance. DAL dal = new DAL(); string SQL = @"INSERT INTO Assets ([AssetName],[AssetType],[Model],[Description], [PurchaseValue],[SalvageValue]

Passing a DateTime value as a parameter to an OleDbCommand

元气小坏坏 提交于 2019-12-06 10:01:01
I have a problem passing a DateTime value to a query as a DbParameter. It seems the time part of the DateTime value gets stripped away. Here is a sample code in C#: DbProviderFactory _factory = OleDbFactory.Instance; DbCommand cmd = _factory.CreateCommand(); cmd.CommandText = "INSERT INTO SomeTable (SomeDateField) VALUES (?)"; DbParameter p = _factory.CreateParameter(); p.ParameterName = ""; // Not necessary p.Value = DateTime.Now; // assume Time != 00:00:00 p.DbType = DbType.Date; // DateTime and DateTime2 don't work cmd.Parameters.Add(p); My problem is that the Date parameter does not seem

C# OleDbParameter with Access DateTime query

自闭症网瘾萝莉.ら 提交于 2019-11-29 16:25:59
I have the following query that works from inside Access or from C# as an OleDbCommand: SELECT Table1.ProductType, Sum(Table1.ProductsSold) FROM Table1 WHERE (Table1.DateTime Between #5/16/2013# And #5/17/2013#) GROUP BY Table1.ProductType; Table1.DateTime is Date/Time data type. Now I want to pass the dates as OleDbParameters. SELECT Table1.ProductType, Sum(Table1.ProductsSold) FROM Table1 WHERE (Table1.DateTime Between #@StartDate# And #@StopDate#) GROUP BY Table1.ProductType; cmd.Parameters.Add(new OleDbParameter("@StartDate", OleDbType.Date)); cmd.Parameters["@StartDate"].Value =

C# OleDbParameter with Access DateTime query

前提是你 提交于 2019-11-28 11:14:58
问题 I have the following query that works from inside Access or from C# as an OleDbCommand: SELECT Table1.ProductType, Sum(Table1.ProductsSold) FROM Table1 WHERE (Table1.DateTime Between #5/16/2013# And #5/17/2013#) GROUP BY Table1.ProductType; Table1.DateTime is Date/Time data type. Now I want to pass the dates as OleDbParameters. SELECT Table1.ProductType, Sum(Table1.ProductsSold) FROM Table1 WHERE (Table1.DateTime Between #@StartDate# And #@StopDate#) GROUP BY Table1.ProductType; cmd

OleDbParameters and Parameter Names

夙愿已清 提交于 2019-11-26 19:04:38
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); 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

OleDbParameters and Parameter Names

隐身守侯 提交于 2019-11-26 06:47:45
问题 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); 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();