473,785 Members | 2,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hashtable to pass to proc

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(stri ng Make, string Model, string Notes)
{
string sql = "spUpdateCa rs";
System.Collecti ons.HashTable params = new System.Collecti ons.HashTables( );
params.add("@ma ke", Make);
params.add("@mo del", Model);
params.add("@no tes", Notes);

this.executeSto redProcedureNon Query(strSQL, params)

}

now the executeStoredPr ocedureNonQuery method:
protected int executeStoredPo rcedureNonQuery (string sqlCommand ,
System.Collecti ons.Hashtable parameters)
{
int result = 0 ;

SqlConnection conn = getConnection() ;
try
{
SqlCommand cmd = new SqlCommand(sqlC ommand, conn) ;
cmd.CommandType = CommandType.Sto redProcedure ;
foreach (DictionaryEntr y parameterEntry in parameters)
{
cmd.Parameters. Add((string)par ameterEntry.Key , parameterEntry. Value) ;

}

cmd.Connection. Open() ;
result = cmd.ExecuteNonQ uery() ;
cmd.Connection. Close() ;
}
catch(SqlExcept ion 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?

Feb 9 '06 #1
4 5294
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*******@disc ussions.microso ft.com> wrote in message
news:F0******** *************** ***********@mic rosoft.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(stri ng Make, string Model, string Notes)
{
string sql = "spUpdateCa rs";
System.Collecti ons.HashTable params = new
System.Collecti ons.HashTables( );
params.add("@ma ke", Make);
params.add("@mo del", Model);
params.add("@no tes", Notes);

this.executeSto redProcedureNon Query(strSQL, params)

}

now the executeStoredPr ocedureNonQuery method:
protected int executeStoredPo rcedureNonQuery (string sqlCommand ,
System.Collecti ons.Hashtable parameters)
{
int result = 0 ;

SqlConnection conn = getConnection() ;
try
{
SqlCommand cmd = new SqlCommand(sqlC ommand, conn) ;
cmd.CommandType = CommandType.Sto redProcedure ;
foreach (DictionaryEntr y parameterEntry in parameters)
{
cmd.Parameters. Add((string)par ameterEntry.Key , parameterEntry. Value) ;

}

cmd.Connection. Open() ;
result = cmd.ExecuteNonQ uery() ;
cmd.Connection. Close() ;
}
catch(SqlExcept ion 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?

Feb 9 '06 #2
I've tried that and still passing in blank and not NULL to the table.
I did something like;
if(parameterEnt ry.value == "")
{
parameterEntry. value = System.DBNull.v alue;
}

and it would not pass NULL to the table, i even checked on the web form
itself,
if (make.text == "")
{
make.text = System.DBNull.v alue;
}

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*******@disc ussions.microso ft.com> wrote in message
news:F0******** *************** ***********@mic rosoft.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(stri ng Make, string Model, string Notes)
{
string sql = "spUpdateCa rs";
System.Collecti ons.HashTable params = new
System.Collecti ons.HashTables( );
params.add("@ma ke", Make);
params.add("@mo del", Model);
params.add("@no tes", Notes);

this.executeSto redProcedureNon Query(strSQL, params)

}

now the executeStoredPr ocedureNonQuery method:
protected int executeStoredPo rcedureNonQuery (string sqlCommand ,
System.Collecti ons.Hashtable parameters)
{
int result = 0 ;

SqlConnection conn = getConnection() ;
try
{
SqlCommand cmd = new SqlCommand(sqlC ommand, conn) ;
cmd.CommandType = CommandType.Sto redProcedure ;
foreach (DictionaryEntr y parameterEntry in parameters)
{
cmd.Parameters. Add((string)par ameterEntry.Key , parameterEntry. Value) ;

}

cmd.Connection. Open() ;
result = cmd.ExecuteNonQ uery() ;
cmd.Connection. Close() ;
}
catch(SqlExcept ion 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?


Feb 9 '06 #3
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*******@disc ussions.microso ft.com> wrote in message
news:CB******** *************** ***********@mic rosoft.com...
I've tried that and still passing in blank and not NULL to the table.
I did something like;
if(parameterEnt ry.value == "")
{
parameterEntry. value = System.DBNull.v alue;
}

and it would not pass NULL to the table, i even checked on the web form
itself,
if (make.text == "")
{
make.text = System.DBNull.v alue;
}

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*******@disc ussions.microso ft.com> wrote in message
news:F0******** *************** ***********@mic rosoft.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(stri ng Make, string Model, string Notes)
> {
> string sql = "spUpdateCa rs";
> System.Collecti ons.HashTable params = new
> System.Collecti ons.HashTables( );
> params.add("@ma ke", Make);
> params.add("@mo del", Model);
> params.add("@no tes", Notes);
>
> this.executeSto redProcedureNon Query(strSQL, params)
>
> }
>
> now the executeStoredPr ocedureNonQuery method:
> protected int executeStoredPo rcedureNonQuery (string sqlCommand ,
> System.Collecti ons.Hashtable parameters)
> {
> int result = 0 ;
>
> SqlConnection conn = getConnection() ;
> try
> {
> SqlCommand cmd = new SqlCommand(sqlC ommand, conn) ;
> cmd.CommandType = CommandType.Sto redProcedure ;
> foreach (DictionaryEntr y parameterEntry in parameters)
> {
> cmd.Parameters. Add((string)par ameterEntry.Key , parameterEntry. Value) ;
>
> }
>
> cmd.Connection. Open() ;
> result = cmd.ExecuteNonQ uery() ;
> cmd.Connection. Close() ;
> }
> catch(SqlExcept ion 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?
>
>
>


Feb 9 '06 #4
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*******@disc ussions.microso ft.com> wrote in message
news:CB******** *************** ***********@mic rosoft.com...
I've tried that and still passing in blank and not NULL to the table.
I did something like;
if(parameterEnt ry.value == "")
{
parameterEntry. value = System.DBNull.v alue;
}

and it would not pass NULL to the table, i even checked on the web form
itself,
if (make.text == "")
{
make.text = System.DBNull.v alue;
}

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*******@disc ussions.microso ft.com> wrote in message
news:F0******** *************** ***********@mic rosoft.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(stri ng Make, string Model, string Notes)
> {
> string sql = "spUpdateCa rs";
> System.Collecti ons.HashTable params = new
> System.Collecti ons.HashTables( );
> params.add("@ma ke", Make);
> params.add("@mo del", Model);
> params.add("@no tes", Notes);
>
> this.executeSto redProcedureNon Query(strSQL, params)
>
> }
>
> now the executeStoredPr ocedureNonQuery method:
> protected int executeStoredPo rcedureNonQuery (string sqlCommand ,
> System.Collecti ons.Hashtable parameters)
> {
> int result = 0 ;
>
> SqlConnection conn = getConnection() ;
> try
> {
> SqlCommand cmd = new SqlCommand(sqlC ommand, conn) ;
> cmd.CommandType = CommandType.Sto redProcedure ;
> foreach (DictionaryEntr y parameterEntry in parameters)
> {
> cmd.Parameters. Add((string)par ameterEntry.Key , parameterEntry. Value) ;
>
> }
>
> cmd.Connection. Open() ;
> result = cmd.ExecuteNonQ uery() ;
> cmd.Connection. Close() ;
> }
> catch(SqlExcept ion 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?
>
>
>


Feb 9 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3621
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, bool firstp = false) const
33
3323
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 used before adding, removing or iterating the Hashtable. The program runs in a high workload environment. After running a few days, now it suddenly catchs this Exception when inserting a pair of key and object, stacktrace =...
3
10167
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 this: public Hashtable Directions; public byte DirectionsSerialized { get
5
1435
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 add handlers to various controls on a form. basically each control would get mostly the same handlers, but there is a particular handler that would vary based on the parent on the control in question. What I would like to do is something like...
5
8562
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, CaseInsensitiveComparer.Default); In v2, this generates the following warnings:
12
4646
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) my problem is: i have to access a temporary table created in an SP in a function
2
4498
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 seperate process. If my windows application starts running,only if it completes fully, then my windows services should continue its execution. My main process is Windows service.
1
4852
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 seperate process. If my windows application starts running,only if it completes fully, then my windows services should continue its execution. My main process is Windows service.
9
3118
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 to store multicast delegates in a hash table, and then fire the delegates one of two ways (after registering/ creating the delegates, etc).
0
9485
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10161
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9958
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8986
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5523
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2890
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.