0

I have a table with some nvarchar(max), varchar(100) and bit type columns. I am inserting values to it programmatically using SQLCommand.ExecuteNonQuery().

I am providing string values to all the nvarchar and varchar columns and 0 or 1 to bit column using SQLParametr.AddWithValue("@parameterName", parameterValue)

For some columns it is storing proper values but for some only null values are getting stored even after providing proper parameter values. Columns in which null values are stored are of type varchar(100) and bit.

In development environment everything works fine, issue occurs in testing environment.

The insert query looks like "INSERT INTO SOME_TABLE(Col1,Col2,Col3,Col4) VAlues(@param1, @param2, @param3, @param4)"

Parameter values are proper even in testing environment tested the same by printing the values to a log file.

Any explanation for this unusual behavior.

Suresh Kumar Veluswamy
  • 4,193
  • 2
  • 20
  • 35
Mac
  • 6,991
  • 8
  • 35
  • 67
  • A concrete answer needs a concrete problem. A handwaving answer would be that this should work, you must be doing something wrong. – Lasse V. Karlsen Jun 12 '15 at 17:13
  • try opening sql profiler and see what is the query being passed to sql server, check the values that are getting passed. there must be something wrong with the values. – Sushil Jun 12 '15 at 17:18
  • Try the insert using the values directly, without using .AddWithValue, and see what the SQL statement looks like. – SteveFerg Jun 12 '15 at 18:36
  • @stevefreg, yes I did that in sql query window, and it is working fine. I will try to dive deep tomorrow – Mac Jun 14 '15 at 07:24

1 Answers1

0

@Lasse V. Karlsen, you were right in a way(A handwaving answer would be that this should work), It turns out to be a silly problem.

All the queries were written in a separate class file which were referenced in the project via add project reference(dll).

I recently made some changes in the class file(Queries) and re-deployed, In dev environment it was working fine but in testing environment, the solution is still referencing the old dll hence old queries, In which I am not passing any values at all and the columns were allow null true, hence storing null values.

Uninstalling the old dll from GAC and installing the new dll fixed the issue

Mac
  • 6,991
  • 8
  • 35
  • 67