Linked Questions

2 votes
2 answers
2k views

I'm trying to execute this command but get an exception: cmd.CommandText = @"insert into Foo (Column1, Column2) values (@Parameter1, @Parameter2)"; cmd.Parameters.Add(new ...
E-Bat's user avatar
  • 4,912
1 vote
2 answers
676 views

I have a list of float? objects. List<float?> myList = new List<float?>{1,null,3}; I'm trying to insert this objects in a table. using (SqlCommand oCommand = myConnection.CreateCommand())...
flofreelance's user avatar
0 votes
1 answer
364 views

Writing data layer code against T-SQL, I often have to add a SqlParameter to a SqlCommand. In the case of a nullable type (for example a DateTime?), I write it like this: if (t.StartDate.HasValue) ...
Alexander's user avatar
0 votes
4 answers
114 views

I have a value which I am trying to add as a parameter to a stored procedure. The value of this parameter could either be a STRING of "1" or "NULL" If it's NULL then I want to add the parameter of ...
Trevor Daniel's user avatar
0 votes
0 answers
46 views

I have a this piece of code below where I'm checking if a value in a certain field is blank ("") and if it is I want to set the value of the SqlParameter to NULL otherwise to the value from the field. ...
psj01's user avatar
  • 3,275
0 votes
0 answers
30 views

I am updating DataTime? column value to null in the database using the Stored procedure and able to update null value in SQL using the same stored procedure. I am using the below code in C#: if(string....
Monika Singh's user avatar
81 votes
14 answers
140k views

I want to write some C# code to initialize my database with some seed data. Clearly, this is going to require the ability to be able to set the values of various Identity columns when inserting. I'm ...
Jez's user avatar
  • 30.5k
110 votes
4 answers
88k views

I have following code for specifying parameters for SQL query. I am getting following exception when I use Code 1; but works fine when I use Code 2. In Code 2 we have a check for null and hence a if.....
LCJ's user avatar
  • 22.8k
43 votes
3 answers
14k views

The following code will not compile: string foo = "bar"; Object o = foo == null ? DBNull.Value : foo; I get: Error 1 Type of conditional expression cannot be determined because there is no implicit ...
mmattax's user avatar
  • 27.8k
18 votes
1 answer
16k views

i've a stored procedure on sqlserver 2008 and one of the parameters accept null values. i don't know how to call that SP with a null value on the parameter. for a little more context i'm using ...
Flavio CF Oliveira's user avatar
5 votes
2 answers
18k views

Before anyone comments that this has been answered before in other question I KNOW that..but in spite of the answers I have reviewed at Assign null to a SqlParameter Sending null parameters to Sql ...
Bastyon's user avatar
  • 1,611
4 votes
1 answer
2k views

I am passing array of SQL Parameters to my wrapper function like SqlParameter[] sqlParams = new SqlParameter[] { new SqlParameter("@UserName",userName), new SqlParameter("@...
user avatar
3 votes
2 answers
1k views

I stumbled across the following issue recently: Assigning a null to the Value property of an SqlParameter appears to cause the parameter to be omitted from the query rather than passing NULL. This ...
Sigurd Garshol's user avatar
1 vote
3 answers
2k views

I want to insert data into a database using a stored procedure, Entity Framework in ASP.NET MVC 5. It works in SQL Server, but when I execute the procedure but in Visual Studio while inserting, I get ...
Basharmal's user avatar
  • 1,394
1 vote
2 answers
1k views

I'm trying to pass a parameter into a stored proc using ADO.NET. This paramater is of type int but the field in the database is nullable. Here's my code: AddInParameter(cmd, "@...
Sperick's user avatar
  • 2,751

15 30 50 per page