I took over an web app (C#) were the developer put everything in a has table
then called a method to execute a stored procedure, now I'm running into some
issues were if I do an update and a NULL is passed that the field in the db
is left empty and NULL is not entered in. So how can I pass a NULL value in a
hashtable, execute the stored procedure and have NULL entered in the table
instead of a blank field?
here is an example of the code:
the call to the stored procedure and passing parameters:
private voide UpdateCars(string Make, string Model, string Notes)
{
string sql = "spUpdateCars";
System.Collections.HashTable params = new System.Collections.HashTables();
params.add("@make", Make);
params.add("@model", Model);
params.add("@notes", Notes);
this.executeStoredProcedureNonQuery(strSQL, params)
}
now the executeStoredProcedureNonQuery method:
protected int executeStoredPorcedureNonQuery(string sqlCommand ,
System.Collections.Hashtable parameters)
{
int result = 0 ;
SqlConnection conn = getConnection() ;
try
{
SqlCommand cmd = new SqlCommand(sqlCommand, conn) ;
cmd.CommandType = CommandType.StoredProcedure ;
foreach (DictionaryEntry parameterEntry in parameters)
{
cmd.Parameters.Add((string)parameterEntry.Key, parameterEntry.Value) ;
}
cmd.Connection.Open() ;
result = cmd.ExecuteNonQuery() ;
cmd.Connection.Close() ;
}
catch(SqlException e)
{
Console.Write(e.StackTrace) ;
}
finally
{
if (conn != null)
conn.Close() ;
}
return result ;
}
so how can i get it to enter NULL in the field and not leave it blank? 4 5257
Maybe you could set the HT value to DbNull, or just have a conditional
statement when you build the SqlCommand where if the value is null, then
insert DbNull. Either way you are using DbNull.
"CsharpGuy" <Cs*******@discussions.microsoft.com> wrote in message
news:F0**********************************@microsof t.com... I took over an web app (C#) were the developer put everything in a has table then called a method to execute a stored procedure, now I'm running into some issues were if I do an update and a NULL is passed that the field in the db is left empty and NULL is not entered in. So how can I pass a NULL value in a hashtable, execute the stored procedure and have NULL entered in the table instead of a blank field?
here is an example of the code: the call to the stored procedure and passing parameters:
private voide UpdateCars(string Make, string Model, string Notes) { string sql = "spUpdateCars"; System.Collections.HashTable params = new System.Collections.HashTables(); params.add("@make", Make); params.add("@model", Model); params.add("@notes", Notes);
this.executeStoredProcedureNonQuery(strSQL, params)
}
now the executeStoredProcedureNonQuery method: protected int executeStoredPorcedureNonQuery(string sqlCommand , System.Collections.Hashtable parameters) { int result = 0 ;
SqlConnection conn = getConnection() ; try { SqlCommand cmd = new SqlCommand(sqlCommand, conn) ; cmd.CommandType = CommandType.StoredProcedure ; foreach (DictionaryEntry parameterEntry in parameters) { cmd.Parameters.Add((string)parameterEntry.Key, parameterEntry.Value) ;
}
cmd.Connection.Open() ; result = cmd.ExecuteNonQuery() ; cmd.Connection.Close() ; } catch(SqlException e) { Console.Write(e.StackTrace) ; } finally { if (conn != null) conn.Close() ; }
return result ; }
so how can i get it to enter NULL in the field and not leave it blank?
I've tried that and still passing in blank and not NULL to the table.
I did something like;
if(parameterEntry.value == "")
{
parameterEntry.value = System.DBNull.value;
}
and it would not pass NULL to the table, i even checked on the web form
itself,
if (make.text == "")
{
make.text = System.DBNull.value;
}
and still nothing,
"Peter Rilling" wrote: Maybe you could set the HT value to DbNull, or just have a conditional statement when you build the SqlCommand where if the value is null, then insert DbNull. Either way you are using DbNull.
"CsharpGuy" <Cs*******@discussions.microsoft.com> wrote in message news:F0**********************************@microsof t.com...I took over an web app (C#) were the developer put everything in a has table then called a method to execute a stored procedure, now I'm running into some issues were if I do an update and a NULL is passed that the field in the db is left empty and NULL is not entered in. So how can I pass a NULL value in a hashtable, execute the stored procedure and have NULL entered in the table instead of a blank field?
here is an example of the code: the call to the stored procedure and passing parameters:
private voide UpdateCars(string Make, string Model, string Notes) { string sql = "spUpdateCars"; System.Collections.HashTable params = new System.Collections.HashTables(); params.add("@make", Make); params.add("@model", Model); params.add("@notes", Notes);
this.executeStoredProcedureNonQuery(strSQL, params)
}
now the executeStoredProcedureNonQuery method: protected int executeStoredPorcedureNonQuery(string sqlCommand , System.Collections.Hashtable parameters) { int result = 0 ;
SqlConnection conn = getConnection() ; try { SqlCommand cmd = new SqlCommand(sqlCommand, conn) ; cmd.CommandType = CommandType.StoredProcedure ; foreach (DictionaryEntry parameterEntry in parameters) { cmd.Parameters.Add((string)parameterEntry.Key, parameterEntry.Value) ;
}
cmd.Connection.Open() ; result = cmd.ExecuteNonQuery() ; cmd.Connection.Close() ; } catch(SqlException e) { Console.Write(e.StackTrace) ; } finally { if (conn != null) conn.Close() ; }
return result ; }
so how can i get it to enter NULL in the field and not leave it blank?
Have you checked to see if it is a problem with the stored procedure? Maybe
the SP has the code to convert nulls into empty strings. Maybe that field
cannot handle nulls.
"CsharpGuy" <Cs*******@discussions.microsoft.com> wrote in message
news:CB**********************************@microsof t.com... I've tried that and still passing in blank and not NULL to the table. I did something like; if(parameterEntry.value == "") { parameterEntry.value = System.DBNull.value; }
and it would not pass NULL to the table, i even checked on the web form itself, if (make.text == "") { make.text = System.DBNull.value; }
and still nothing,
"Peter Rilling" wrote:
Maybe you could set the HT value to DbNull, or just have a conditional statement when you build the SqlCommand where if the value is null, then insert DbNull. Either way you are using DbNull.
"CsharpGuy" <Cs*******@discussions.microsoft.com> wrote in message news:F0**********************************@microsof t.com... >I took over an web app (C#) were the developer put everything in a has >table > then called a method to execute a stored procedure, now I'm running > into > some > issues were if I do an update and a NULL is passed that the field in > the > db > is left empty and NULL is not entered in. So how can I pass a NULL > value > in a > hashtable, execute the stored procedure and have NULL entered in the > table > instead of a blank field? > > here is an example of the code: > the call to the stored procedure and passing parameters: > > private voide UpdateCars(string Make, string Model, string Notes) > { > string sql = "spUpdateCars"; > System.Collections.HashTable params = new > System.Collections.HashTables(); > params.add("@make", Make); > params.add("@model", Model); > params.add("@notes", Notes); > > this.executeStoredProcedureNonQuery(strSQL, params) > > } > > now the executeStoredProcedureNonQuery method: > protected int executeStoredPorcedureNonQuery(string sqlCommand , > System.Collections.Hashtable parameters) > { > int result = 0 ; > > SqlConnection conn = getConnection() ; > try > { > SqlCommand cmd = new SqlCommand(sqlCommand, conn) ; > cmd.CommandType = CommandType.StoredProcedure ; > foreach (DictionaryEntry parameterEntry in parameters) > { > cmd.Parameters.Add((string)parameterEntry.Key, parameterEntry.Value) ; > > } > > cmd.Connection.Open() ; > result = cmd.ExecuteNonQuery() ; > cmd.Connection.Close() ; > } > catch(SqlException e) > { > Console.Write(e.StackTrace) ; > } > finally > { > if (conn != null) > conn.Close() ; > } > > return result ; > } > > so how can i get it to enter NULL in the field and not leave it blank? > > >
The field in the table allows NULLS.
The procs looks like this
create procedure spUpdateCars
{
@salesID int,
@make char(25) = NULL,
@model char(20) = NULL,
@notes varchar(250) = NULL
},
update Cars
set
CarMake = @make,
CarModel = @model,
SaleNotes = @notes
where sales ID = @salesID
is this how it should look to allow NULLS and insert NULL in the table or no?
"Peter Rilling" wrote: Have you checked to see if it is a problem with the stored procedure? Maybe the SP has the code to convert nulls into empty strings. Maybe that field cannot handle nulls.
"CsharpGuy" <Cs*******@discussions.microsoft.com> wrote in message news:CB**********************************@microsof t.com... I've tried that and still passing in blank and not NULL to the table. I did something like; if(parameterEntry.value == "") { parameterEntry.value = System.DBNull.value; }
and it would not pass NULL to the table, i even checked on the web form itself, if (make.text == "") { make.text = System.DBNull.value; }
and still nothing,
"Peter Rilling" wrote:
Maybe you could set the HT value to DbNull, or just have a conditional statement when you build the SqlCommand where if the value is null, then insert DbNull. Either way you are using DbNull.
"CsharpGuy" <Cs*******@discussions.microsoft.com> wrote in message news:F0**********************************@microsof t.com... >I took over an web app (C#) were the developer put everything in a has >table > then called a method to execute a stored procedure, now I'm running > into > some > issues were if I do an update and a NULL is passed that the field in > the > db > is left empty and NULL is not entered in. So how can I pass a NULL > value > in a > hashtable, execute the stored procedure and have NULL entered in the > table > instead of a blank field? > > here is an example of the code: > the call to the stored procedure and passing parameters: > > private voide UpdateCars(string Make, string Model, string Notes) > { > string sql = "spUpdateCars"; > System.Collections.HashTable params = new > System.Collections.HashTables(); > params.add("@make", Make); > params.add("@model", Model); > params.add("@notes", Notes); > > this.executeStoredProcedureNonQuery(strSQL, params) > > } > > now the executeStoredProcedureNonQuery method: > protected int executeStoredPorcedureNonQuery(string sqlCommand , > System.Collections.Hashtable parameters) > { > int result = 0 ; > > SqlConnection conn = getConnection() ; > try > { > SqlCommand cmd = new SqlCommand(sqlCommand, conn) ; > cmd.CommandType = CommandType.StoredProcedure ; > foreach (DictionaryEntry parameterEntry in parameters) > { > cmd.Parameters.Add((string)parameterEntry.Key, parameterEntry.Value) ; > > } > > cmd.Connection.Open() ; > result = cmd.ExecuteNonQuery() ; > cmd.Connection.Close() ; > } > catch(SqlException e) > { > Console.Write(e.StackTrace) ; > } > finally > { > if (conn != null) > conn.Close() ; > } > > return result ; > } > > so how can i get it to enter NULL in the field and not leave it blank? > > > This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Billy Patton |
last post by:
I've had a lot of help, but I need a little more.
Here's a snippett of code:
template <typename K,typename V>
class HashTable : private std::map<K, V>
{
private:
public:
bool Keys(K& key,...
|
by: Ken |
last post by:
I have a C# Program where multiple threads will operate on a same Hashtable.
This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable)
method, so no further Lock statements are...
|
by: MioTheGreat |
last post by:
I know how to take a single hashtable, and then use a binaryformatter
and a filestream to dump it to a file, but I need to serialize and
deserialize a hashtable inside a class. I've been trying...
|
by: Mike Hoff |
last post by:
Hello,
I am wondering if it is possible to pass a procedure name to another proc.
I have been looking into delegates, but cannot seem to get the code correct.
Basically what I have is a proc to...
|
by: Mark Rae |
last post by:
Hi,
In v1.x, I used to use the following code to create a case-insensitive
Hashtable:
Hashtable MyHashtable = new
Hashtable(CaseInsensitiveHashCodeProvider.Default,...
|
by: ArunDhaJ |
last post by:
Hi Friends,
Is it possible to pass a table as a parameter to a funtion.
whos function declaration would look some thing like this....
ALTER FUNCTION TempFunction (@TempTable TABLE, @nPId INT)
...
|
by: =?Utf-8?B?dmlzaHJ1dGg=?= |
last post by:
Hi,
I have 2 applications running, one Windows application project and the other
windows services project.
I want to call my Windows application in my windows services.
I want to run them as...
|
by: =?Utf-8?B?dmlzaHJ1dGg=?= |
last post by:
Hi,
I have 2 applications running, one Windows application project and the other
windows services project.
I want to call my Windows application in my windows services.
I want to run them as...
|
by: raylopez99 |
last post by:
Hello all—
I’m trying to get the below to work and cannot get the format right.
It’s from this example: http://msdn.microsoft.com/en-us/library/8627sbea(VS.71).aspx
What it is: I’m trying...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |