PC Review


Reply
Thread Tools Rate Thread

ADO.NET paremeters

 
 
=?Utf-8?B?V1hNQ0RCQQ==?=
Guest
Posts: n/a
 
      27th Dec 2005
Hi everyone. I have a small problem that I can not seem to resolve. I am
executing a stored procedure using the ExecuteReader method. However it is
failing. Here is my code in short. I debugged it using Sql profiler it
appears that my currentdatetime parameter is going to the next line and I am
not sure why, but I am positive that this is the reason it is failing. The
output is below the code.

SqlParameter physID = cmd.Parameters.Add("@phys_id", SqlDbType.Int);
SqlParameter lName = cmd.Parameters.Add("@lname",
SqlDbType.VarChar, 25);
SqlParameter fName = cmd.Parameters.Add("@fname",
SqlDbType.VarChar, 15);
SqlParameter mName = cmd.Parameters.Add("@mname",
SqlDbType.VarChar, 15);
SqlParameter suffixCode =
cmd.Parameters.Add("@suffix_code", SqlDbType.Char, 4);
SqlParameter legalNameInd =
cmd.Parameters.Add("@legal_name_ind", SqlDbType.Char, 1);
SqlParameter insertLogin =
cmd.Parameters.Add("@insert_login", SqlDbType.VarChar, 30);
SqlParameter currentDateTime =
cmd.Parameters.Add("@currentdatetime", SqlDbType.VarChar, 30);
SqlParameter rc = cmd.Parameters.Add("@rc",
SqlDbType.Int);

//Set the parameter values.
physID.Value = physician.PhysId;
lName.Value = physician.LastName;
fName.Value = physician.FirstName;
mName.Value = physician.MidName;
suffixCode.Value = physician.SuffixCode;
legalNameInd.Value = physician.LegalNameInd;
insertLogin.Value = currentUser.Username;
currentDateTime.Value = date;
rc.Value = 0;

rdr = cmd.ExecuteReader();
rdr.Close();

exec phys_names_isp1
@phys_id=34219,@lname='Test4',@fname='Test4',@mname='',@suffix_code=default,@legal_name_ind='Y',@insert_login='kareno_rmf',@currentdatetime='12/27/2005
3:53:43 PM',@rc=0
 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      27th Dec 2005
2 thoughts:

1. The newline may be due to lack of spaces in the beginning of the call,
and the profiler is just trying to find a place to wrap. So it may not be a
true newline
2. You are declaring the currentdatetime parameter as a Varchar 30. Why?
This should be declared as a datetime parameter. What is happening right
now, is that ToString() is being called on your date object, and that is
being sent. If you are trying to put that value into a column declared as
datetime, then it is failing because it cannot parse what you are giving it.
Calling ToString on a datetime is just returning a default string
representation of the date object, which is not necessarily compatible with
what the database parser expects. Not to mention that if someone has any
sort of date format settings set, etc, that what this method returns will
vary.

"WXMCDBA" <(E-Mail Removed)> wrote in message
news:0F3E0675-2D87-4D42-B646-(E-Mail Removed)...
> Hi everyone. I have a small problem that I can not seem to resolve. I am
> executing a stored procedure using the ExecuteReader method. However it is
> failing. Here is my code in short. I debugged it using Sql profiler it
> appears that my currentdatetime parameter is going to the next line and I
> am
> not sure why, but I am positive that this is the reason it is failing. The
> output is below the code.
>
> SqlParameter physID = cmd.Parameters.Add("@phys_id", SqlDbType.Int);
> SqlParameter lName = cmd.Parameters.Add("@lname",
> SqlDbType.VarChar, 25);
> SqlParameter fName = cmd.Parameters.Add("@fname",
> SqlDbType.VarChar, 15);
> SqlParameter mName = cmd.Parameters.Add("@mname",
> SqlDbType.VarChar, 15);
> SqlParameter suffixCode =
> cmd.Parameters.Add("@suffix_code", SqlDbType.Char, 4);
> SqlParameter legalNameInd =
> cmd.Parameters.Add("@legal_name_ind", SqlDbType.Char, 1);
> SqlParameter insertLogin =
> cmd.Parameters.Add("@insert_login", SqlDbType.VarChar, 30);
> SqlParameter currentDateTime =
> cmd.Parameters.Add("@currentdatetime", SqlDbType.VarChar, 30);
> SqlParameter rc = cmd.Parameters.Add("@rc",
> SqlDbType.Int);
>
> //Set the parameter values.
> physID.Value = physician.PhysId;
> lName.Value = physician.LastName;
> fName.Value = physician.FirstName;
> mName.Value = physician.MidName;
> suffixCode.Value = physician.SuffixCode;
> legalNameInd.Value = physician.LegalNameInd;
> insertLogin.Value = currentUser.Username;
> currentDateTime.Value = date;
> rc.Value = 0;
>
> rdr = cmd.ExecuteReader();
> rdr.Close();
>
> exec phys_names_isp1
> @phys_id=34219,@lname='Test4',@fname='Test4',@mname='',@suffix_code=default,@legal_name_ind='Y',@insert_login='kareno_rmf',@currentdatetime='12/27/2005
> 3:53:43 PM',@rc=0



 
Reply With Quote
 
=?Utf-8?B?S2VycnkgTW9vcm1hbg==?=
Guest
Posts: n/a
 
      27th Dec 2005
WXMCDBA,

Should the @currentdatetime parameter be SqlDbType.DateTime instead of
SqlDbType.VarChar?

Kerry Moorman


"WXMCDBA" wrote:

> Hi everyone. I have a small problem that I can not seem to resolve. I am
> executing a stored procedure using the ExecuteReader method. However it is
> failing. Here is my code in short. I debugged it using Sql profiler it
> appears that my currentdatetime parameter is going to the next line and I am
> not sure why, but I am positive that this is the reason it is failing. The
> output is below the code.
>
> SqlParameter physID = cmd.Parameters.Add("@phys_id", SqlDbType.Int);
> SqlParameter lName = cmd.Parameters.Add("@lname",
> SqlDbType.VarChar, 25);
> SqlParameter fName = cmd.Parameters.Add("@fname",
> SqlDbType.VarChar, 15);
> SqlParameter mName = cmd.Parameters.Add("@mname",
> SqlDbType.VarChar, 15);
> SqlParameter suffixCode =
> cmd.Parameters.Add("@suffix_code", SqlDbType.Char, 4);
> SqlParameter legalNameInd =
> cmd.Parameters.Add("@legal_name_ind", SqlDbType.Char, 1);
> SqlParameter insertLogin =
> cmd.Parameters.Add("@insert_login", SqlDbType.VarChar, 30);
> SqlParameter currentDateTime =
> cmd.Parameters.Add("@currentdatetime", SqlDbType.VarChar, 30);
> SqlParameter rc = cmd.Parameters.Add("@rc",
> SqlDbType.Int);
>
> //Set the parameter values.
> physID.Value = physician.PhysId;
> lName.Value = physician.LastName;
> fName.Value = physician.FirstName;
> mName.Value = physician.MidName;
> suffixCode.Value = physician.SuffixCode;
> legalNameInd.Value = physician.LegalNameInd;
> insertLogin.Value = currentUser.Username;
> currentDateTime.Value = date;
> rc.Value = 0;
>
> rdr = cmd.ExecuteReader();
> rdr.Close();
>
> exec phys_names_isp1
> @phys_id=34219,@lname='Test4',@fname='Test4',@mname='',@suffix_code=default,@legal_name_ind='Y',@insert_login='kareno_rmf',@currentdatetime='12/27/2005
> 3:53:43 PM',@rc=0

 
Reply With Quote
 
=?Utf-8?B?V1hNQ0RCQQ==?=
Guest
Posts: n/a
 
      28th Dec 2005
Thank you for your respsonse.

William Xifaras, MCDBA

"Kerry Moorman" wrote:

> WXMCDBA,
>
> Should the @currentdatetime parameter be SqlDbType.DateTime instead of
> SqlDbType.VarChar?
>
> Kerry Moorman
>
>
> "WXMCDBA" wrote:
>
> > Hi everyone. I have a small problem that I can not seem to resolve. I am
> > executing a stored procedure using the ExecuteReader method. However it is
> > failing. Here is my code in short. I debugged it using Sql profiler it
> > appears that my currentdatetime parameter is going to the next line and I am
> > not sure why, but I am positive that this is the reason it is failing. The
> > output is below the code.
> >
> > SqlParameter physID = cmd.Parameters.Add("@phys_id", SqlDbType.Int);
> > SqlParameter lName = cmd.Parameters.Add("@lname",
> > SqlDbType.VarChar, 25);
> > SqlParameter fName = cmd.Parameters.Add("@fname",
> > SqlDbType.VarChar, 15);
> > SqlParameter mName = cmd.Parameters.Add("@mname",
> > SqlDbType.VarChar, 15);
> > SqlParameter suffixCode =
> > cmd.Parameters.Add("@suffix_code", SqlDbType.Char, 4);
> > SqlParameter legalNameInd =
> > cmd.Parameters.Add("@legal_name_ind", SqlDbType.Char, 1);
> > SqlParameter insertLogin =
> > cmd.Parameters.Add("@insert_login", SqlDbType.VarChar, 30);
> > SqlParameter currentDateTime =
> > cmd.Parameters.Add("@currentdatetime", SqlDbType.VarChar, 30);
> > SqlParameter rc = cmd.Parameters.Add("@rc",
> > SqlDbType.Int);
> >
> > //Set the parameter values.
> > physID.Value = physician.PhysId;
> > lName.Value = physician.LastName;
> > fName.Value = physician.FirstName;
> > mName.Value = physician.MidName;
> > suffixCode.Value = physician.SuffixCode;
> > legalNameInd.Value = physician.LegalNameInd;
> > insertLogin.Value = currentUser.Username;
> > currentDateTime.Value = date;
> > rc.Value = 0;
> >
> > rdr = cmd.ExecuteReader();
> > rdr.Close();
> >
> > exec phys_names_isp1
> > @phys_id=34219,@lname='Test4',@fname='Test4',@mname='',@suffix_code=default,@legal_name_ind='Y',@insert_login='kareno_rmf',@currentdatetime='12/27/2005
> > 3:53:43 PM',@rc=0

 
Reply With Quote
 
=?Utf-8?B?V1hNQ0RCQQ==?=
Guest
Posts: n/a
 
      28th Dec 2005
Thank you for your response.

William Xifaras, MCDBA

"Marina" wrote:

> 2 thoughts:
>
> 1. The newline may be due to lack of spaces in the beginning of the call,
> and the profiler is just trying to find a place to wrap. So it may not be a
> true newline
> 2. You are declaring the currentdatetime parameter as a Varchar 30. Why?
> This should be declared as a datetime parameter. What is happening right
> now, is that ToString() is being called on your date object, and that is
> being sent. If you are trying to put that value into a column declared as
> datetime, then it is failing because it cannot parse what you are giving it.
> Calling ToString on a datetime is just returning a default string
> representation of the date object, which is not necessarily compatible with
> what the database parser expects. Not to mention that if someone has any
> sort of date format settings set, etc, that what this method returns will
> vary.
>
> "WXMCDBA" <(E-Mail Removed)> wrote in message
> news:0F3E0675-2D87-4D42-B646-(E-Mail Removed)...
> > Hi everyone. I have a small problem that I can not seem to resolve. I am
> > executing a stored procedure using the ExecuteReader method. However it is
> > failing. Here is my code in short. I debugged it using Sql profiler it
> > appears that my currentdatetime parameter is going to the next line and I
> > am
> > not sure why, but I am positive that this is the reason it is failing. The
> > output is below the code.
> >
> > SqlParameter physID = cmd.Parameters.Add("@phys_id", SqlDbType.Int);
> > SqlParameter lName = cmd.Parameters.Add("@lname",
> > SqlDbType.VarChar, 25);
> > SqlParameter fName = cmd.Parameters.Add("@fname",
> > SqlDbType.VarChar, 15);
> > SqlParameter mName = cmd.Parameters.Add("@mname",
> > SqlDbType.VarChar, 15);
> > SqlParameter suffixCode =
> > cmd.Parameters.Add("@suffix_code", SqlDbType.Char, 4);
> > SqlParameter legalNameInd =
> > cmd.Parameters.Add("@legal_name_ind", SqlDbType.Char, 1);
> > SqlParameter insertLogin =
> > cmd.Parameters.Add("@insert_login", SqlDbType.VarChar, 30);
> > SqlParameter currentDateTime =
> > cmd.Parameters.Add("@currentdatetime", SqlDbType.VarChar, 30);
> > SqlParameter rc = cmd.Parameters.Add("@rc",
> > SqlDbType.Int);
> >
> > //Set the parameter values.
> > physID.Value = physician.PhysId;
> > lName.Value = physician.LastName;
> > fName.Value = physician.FirstName;
> > mName.Value = physician.MidName;
> > suffixCode.Value = physician.SuffixCode;
> > legalNameInd.Value = physician.LegalNameInd;
> > insertLogin.Value = currentUser.Username;
> > currentDateTime.Value = date;
> > rc.Value = 0;
> >
> > rdr = cmd.ExecuteReader();
> > rdr.Close();
> >
> > exec phys_names_isp1
> > @phys_id=34219,@lname='Test4',@fname='Test4',@mname='',@suffix_code=default,@legal_name_ind='Y',@insert_login='kareno_rmf',@currentdatetime='12/27/2005
> > 3:53:43 PM',@rc=0

>
>
>

 
Reply With Quote
 
=?Utf-8?B?V1hNQ0RCQQ==?=
Guest
Posts: n/a
 
      28th Dec 2005
Marina I orginally had the currentdatetime parameter as a datetime and this
is what the output looked like. If you look at the output now you will see
two single quotes and a new line. Thanks again.

William Xifaras, MCDBA

exec phys_names_isp1
@phys_id=34219,@lname='Test4',@fname='Test4',@mname='',@suffix_code=default,@legal_name_ind='Y',@insert_login='kareno_rmf',@currentdatetime=''2005-12-28
09:30:09:080'',@rc=0
go

"Marina" wrote:

> 2 thoughts:
>
> 1. The newline may be due to lack of spaces in the beginning of the call,
> and the profiler is just trying to find a place to wrap. So it may not be a
> true newline
> 2. You are declaring the currentdatetime parameter as a Varchar 30. Why?
> This should be declared as a datetime parameter. What is happening right
> now, is that ToString() is being called on your date object, and that is
> being sent. If you are trying to put that value into a column declared as
> datetime, then it is failing because it cannot parse what you are giving it.
> Calling ToString on a datetime is just returning a default string
> representation of the date object, which is not necessarily compatible with
> what the database parser expects. Not to mention that if someone has any
> sort of date format settings set, etc, that what this method returns will
> vary.
>
> "WXMCDBA" <(E-Mail Removed)> wrote in message
> news:0F3E0675-2D87-4D42-B646-(E-Mail Removed)...
> > Hi everyone. I have a small problem that I can not seem to resolve. I am
> > executing a stored procedure using the ExecuteReader method. However it is
> > failing. Here is my code in short. I debugged it using Sql profiler it
> > appears that my currentdatetime parameter is going to the next line and I
> > am
> > not sure why, but I am positive that this is the reason it is failing. The
> > output is below the code.
> >
> > SqlParameter physID = cmd.Parameters.Add("@phys_id", SqlDbType.Int);
> > SqlParameter lName = cmd.Parameters.Add("@lname",
> > SqlDbType.VarChar, 25);
> > SqlParameter fName = cmd.Parameters.Add("@fname",
> > SqlDbType.VarChar, 15);
> > SqlParameter mName = cmd.Parameters.Add("@mname",
> > SqlDbType.VarChar, 15);
> > SqlParameter suffixCode =
> > cmd.Parameters.Add("@suffix_code", SqlDbType.Char, 4);
> > SqlParameter legalNameInd =
> > cmd.Parameters.Add("@legal_name_ind", SqlDbType.Char, 1);
> > SqlParameter insertLogin =
> > cmd.Parameters.Add("@insert_login", SqlDbType.VarChar, 30);
> > SqlParameter currentDateTime =
> > cmd.Parameters.Add("@currentdatetime", SqlDbType.VarChar, 30);
> > SqlParameter rc = cmd.Parameters.Add("@rc",
> > SqlDbType.Int);
> >
> > //Set the parameter values.
> > physID.Value = physician.PhysId;
> > lName.Value = physician.LastName;
> > fName.Value = physician.FirstName;
> > mName.Value = physician.MidName;
> > suffixCode.Value = physician.SuffixCode;
> > legalNameInd.Value = physician.LegalNameInd;
> > insertLogin.Value = currentUser.Username;
> > currentDateTime.Value = date;
> > rc.Value = 0;
> >
> > rdr = cmd.ExecuteReader();
> > rdr.Close();
> >
> > exec phys_names_isp1
> > @phys_id=34219,@lname='Test4',@fname='Test4',@mname='',@suffix_code=default,@legal_name_ind='Y',@insert_login='kareno_rmf',@currentdatetime='12/27/2005
> > 3:53:43 PM',@rc=0

>
>
>

 
Reply With Quote
 
=?Utf-8?B?V1hNQ0RCQQ==?=
Guest
Posts: n/a
 
      28th Dec 2005
My code is working. I feel so foolish. I am using the new System.Transactions
namespace and I was missing a commit in my code so the code was rolling
back...ughhh
I guess these things happen

"Kerry Moorman" wrote:

> WXMCDBA,
>
> Should the @currentdatetime parameter be SqlDbType.DateTime instead of
> SqlDbType.VarChar?
>
> Kerry Moorman
>
>
> "WXMCDBA" wrote:
>
> > Hi everyone. I have a small problem that I can not seem to resolve. I am
> > executing a stored procedure using the ExecuteReader method. However it is
> > failing. Here is my code in short. I debugged it using Sql profiler it
> > appears that my currentdatetime parameter is going to the next line and I am
> > not sure why, but I am positive that this is the reason it is failing. The
> > output is below the code.
> >
> > SqlParameter physID = cmd.Parameters.Add("@phys_id", SqlDbType.Int);
> > SqlParameter lName = cmd.Parameters.Add("@lname",
> > SqlDbType.VarChar, 25);
> > SqlParameter fName = cmd.Parameters.Add("@fname",
> > SqlDbType.VarChar, 15);
> > SqlParameter mName = cmd.Parameters.Add("@mname",
> > SqlDbType.VarChar, 15);
> > SqlParameter suffixCode =
> > cmd.Parameters.Add("@suffix_code", SqlDbType.Char, 4);
> > SqlParameter legalNameInd =
> > cmd.Parameters.Add("@legal_name_ind", SqlDbType.Char, 1);
> > SqlParameter insertLogin =
> > cmd.Parameters.Add("@insert_login", SqlDbType.VarChar, 30);
> > SqlParameter currentDateTime =
> > cmd.Parameters.Add("@currentdatetime", SqlDbType.VarChar, 30);
> > SqlParameter rc = cmd.Parameters.Add("@rc",
> > SqlDbType.Int);
> >
> > //Set the parameter values.
> > physID.Value = physician.PhysId;
> > lName.Value = physician.LastName;
> > fName.Value = physician.FirstName;
> > mName.Value = physician.MidName;
> > suffixCode.Value = physician.SuffixCode;
> > legalNameInd.Value = physician.LegalNameInd;
> > insertLogin.Value = currentUser.Username;
> > currentDateTime.Value = date;
> > rc.Value = 0;
> >
> > rdr = cmd.ExecuteReader();
> > rdr.Close();
> >
> > exec phys_names_isp1
> > @phys_id=34219,@lname='Test4',@fname='Test4',@mname='',@suffix_code=default,@legal_name_ind='Y',@insert_login='kareno_rmf',@currentdatetime='12/27/2005
> > 3:53:43 PM',@rc=0

 
Reply With Quote
 
=?Utf-8?B?V1hNQ0RCQQ==?=
Guest
Posts: n/a
 
      28th Dec 2005
My code is working. I feel so foolish. I am using the new System.Transactions
namespace and I was missing a commit in my code so the code was rolling
back...ughhh
I guess these things happen

"Marina" wrote:

> 2 thoughts:
>
> 1. The newline may be due to lack of spaces in the beginning of the call,
> and the profiler is just trying to find a place to wrap. So it may not be a
> true newline
> 2. You are declaring the currentdatetime parameter as a Varchar 30. Why?
> This should be declared as a datetime parameter. What is happening right
> now, is that ToString() is being called on your date object, and that is
> being sent. If you are trying to put that value into a column declared as
> datetime, then it is failing because it cannot parse what you are giving it.
> Calling ToString on a datetime is just returning a default string
> representation of the date object, which is not necessarily compatible with
> what the database parser expects. Not to mention that if someone has any
> sort of date format settings set, etc, that what this method returns will
> vary.
>
> "WXMCDBA" <(E-Mail Removed)> wrote in message
> news:0F3E0675-2D87-4D42-B646-(E-Mail Removed)...
> > Hi everyone. I have a small problem that I can not seem to resolve. I am
> > executing a stored procedure using the ExecuteReader method. However it is
> > failing. Here is my code in short. I debugged it using Sql profiler it
> > appears that my currentdatetime parameter is going to the next line and I
> > am
> > not sure why, but I am positive that this is the reason it is failing. The
> > output is below the code.
> >
> > SqlParameter physID = cmd.Parameters.Add("@phys_id", SqlDbType.Int);
> > SqlParameter lName = cmd.Parameters.Add("@lname",
> > SqlDbType.VarChar, 25);
> > SqlParameter fName = cmd.Parameters.Add("@fname",
> > SqlDbType.VarChar, 15);
> > SqlParameter mName = cmd.Parameters.Add("@mname",
> > SqlDbType.VarChar, 15);
> > SqlParameter suffixCode =
> > cmd.Parameters.Add("@suffix_code", SqlDbType.Char, 4);
> > SqlParameter legalNameInd =
> > cmd.Parameters.Add("@legal_name_ind", SqlDbType.Char, 1);
> > SqlParameter insertLogin =
> > cmd.Parameters.Add("@insert_login", SqlDbType.VarChar, 30);
> > SqlParameter currentDateTime =
> > cmd.Parameters.Add("@currentdatetime", SqlDbType.VarChar, 30);
> > SqlParameter rc = cmd.Parameters.Add("@rc",
> > SqlDbType.Int);
> >
> > //Set the parameter values.
> > physID.Value = physician.PhysId;
> > lName.Value = physician.LastName;
> > fName.Value = physician.FirstName;
> > mName.Value = physician.MidName;
> > suffixCode.Value = physician.SuffixCode;
> > legalNameInd.Value = physician.LegalNameInd;
> > insertLogin.Value = currentUser.Username;
> > currentDateTime.Value = date;
> > rc.Value = 0;
> >
> > rdr = cmd.ExecuteReader();
> > rdr.Close();
> >
> > exec phys_names_isp1
> > @phys_id=34219,@lname='Test4',@fname='Test4',@mname='',@suffix_code=default,@legal_name_ind='Y',@insert_login='kareno_rmf',@currentdatetime='12/27/2005
> > 3:53:43 PM',@rc=0

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Crosstab query with date paremeters =?Utf-8?B?TGlzYQ==?= Microsoft Access Queries 1 7th Mar 2006 09:18 PM
time paremeters for appointments =?Utf-8?B?UGVubnkgTG91?= Microsoft Outlook Discussion 1 1st Dec 2005 05:49 PM
Too Few Paremeters - Error 3061 LisaB Microsoft Access VBA Modules 2 12th Apr 2005 04:27 PM
Passing Paremeters from Form to Crystal Report lewindha Microsoft ASP .NET 0 4th Nov 2004 04:58 PM
How to make queries with paremeters Diego F. Microsoft ADO .NET 1 28th Aug 2004 07:16 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:34 AM.