Questions tagged [dbcommand]
38 questions
31
votes
7 answers
How to generate List from SQL query?
If I have a DbCommand defined to execute something like:
SELECT Column1 FROM Table1
What is the best way to generate a List of the returned records?
No Linq etc. as I am using VS2005.

CJ7
- 22,579
- 65
- 193
- 321
26
votes
4 answers
Inserting NULL to SQL DB from C# DbCommand
DbParameter param = comm.CreateParameter();
param = comm.CreateParameter();
param.ParameterName = "@StaffId";
if (!string.IsNullOrEmpty(activity.StaffId))
param.Value = activity.StaffId;
…

SkonJeet
- 4,827
- 4
- 23
- 32
21
votes
3 answers
Why the "Non" in "ExecuteNonQuery"?
I know this is not a hell of an useful question but I can't help being bugged by it.
So,
Why said method (in *Command classes) is called
ExecuteNonQuery instead of ExecuteQuery?
Aren't those SQL statements we throw at DBs, queries?

Camilo Martin
- 37,236
- 20
- 111
- 154
10
votes
3 answers
SQL0666 - SQL query exceeds specified time limit or storage limit
Periodically, I get this error message while making a call to a DB2 database using the Odbc connection string. I have tried setting the CommandTimeout of the DbCommand object to multiple values, but I still get the following error.
SQL0666 - SQL…

Isaac Levin
- 101
- 1
- 1
- 3
9
votes
6 answers
Copy parameters from DbCommand to another DbCommand
How do you copy DbCommand parameters to another DbCommand, I want a new DbCommand with the same parameters as my last DbCommand. But now with a different sql string.

Aivan Monceller
- 4,636
- 10
- 42
- 69
7
votes
3 answers
Generic way to catch Unique Key Violation
I use System.Data.Common.DbCommand to insert a new row to database. The point is, that this row already exists.
try
{
[...]
DbCommand insertCommand = [...]
insertCommand.ExecuteScalar();
[...]
}
catch (System.Exception exception)
{
…

kbisang
- 558
- 4
- 13
5
votes
1 answer
SqlParameter DbType.Date -> SqlDbType.DateTime Conversion
I'm using the generic IDbCommand functions (in non SqlCommand helper methods) to set SqlCommand.DbType to DbType.Date similar to this:
var param = command.CreateParameter();
param.DbType = DbType.Date;
param.ParameterName =…

Gene
- 1,587
- 4
- 18
- 38
4
votes
3 answers
Is order of parameters for database Command object really important?
I was debugging a database operation code and I found that proper UPDATE was never happening though the code never failed as such. This is the code:
condb.Open();
OleDbCommand dbcom = new OleDbCommand("UPDATE Word SET…

nawfal
- 70,104
- 56
- 326
- 368
4
votes
2 answers
Why SQL Server SHOWPLAN_XML via DbCommand(Parameterized) is not return results?
I wish to collect Query plan via C# for improve development.
My approach is use DbCommand and SET SHOWPLAN_XML ON
But...
Non-parameterized query will return query plan collectly.
Parameterized query will return nothing!
Both SQL Server 2008 R2 and…

Lyc
- 121
- 8
3
votes
1 answer
DbCommand with Linq?
I'm using DbCommand from : System.ComponentModel.Component
I'm building an object with params :
DbCommand command = _webERPDB.GetStoredProcCommand("mySp");
_webERPDB.AddInParameter(command, "@a", DbType.Int32,…

Royi Namir
- 144,742
- 138
- 468
- 792
3
votes
2 answers
How to Convert a Nullable DateTime variable's null value to DbNull.Value
I have a nullable DateTime Variable. And I want to write it to SQL DB. When i try to insert:
If the variable has value there is no problem.
But if it hasn't a value, insertion interrupting with an error.
I want to ask: How can we insert nullable…

DortGen
- 402
- 2
- 8
- 22
3
votes
0 answers
Microsoft.EntityFrameworkCore.Database.Command Failed executing DbCommand (size=-1)
I don't know why parameter 8 has size of -1. In EntityFramework, this property has a maxlength of 75 and the column in the database is a nvarchar(75). It's the only parameter to have wrong size.
[2022-11-01 00:13:30.381 -04:00] [Error] [AC-PEL1:73]…

Eric Caron
- 41
- 2
3
votes
2 answers
DbCommand can't run multiple SQL command in one ExecuteNonQuery()
Hello I have the following problem and I can't solve it.
With DbCommand I'm trying execute this SQL statement
Dim strCommnad As String =
"CREATE DEFAULT [dbo].[DOMAIN_XLibPKID_D] AS (0);" + Environment.NewLine + …

Mac
- 31
- 2
3
votes
2 answers
ASP.NET: How to support two database types in one application? (Access, MS SQL Server 2008 Express)
The ASP.NET web application I am developing needs to support two different types of databases, namely Access and MS SQL Server 2008 Express.
I already have connection strings for each database type stored in web.config, and I have another web.config…

Jeremy
- 3,221
- 7
- 27
- 31
3
votes
0 answers
Injecting custom IDbCommand in NHibernate
We use Fluent NHibernate with SQL server 2008. I need NHibernate to use my custom DbCommand class (inherited from IDbCommand). In this custom DbCommand class, I want to handle transient errors (e.g. any transient network errors etc...) and retry the…

user3698855
- 31
- 1