.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 19th, 2011, 03:56 PM
confuseddotcom confuseddotcom is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 2 confuseddotcom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 49 sec
Reputation Power: 0
Trouble using ADODB to call a stored proc

Hi,

I have wasted most of my afternoon trying to figure this out - apologies if it turns out to be trivial.

I am using the following code to call a stored proc:

c# Code:
Original - c# Code
  1. private void butTestCode_Click(object sender, EventArgs e)
  2.         {
  3.             ADODB.Connection con;
  4.             ADODB.Command com;
  5.             ADODB.Recordset rst;
  6.             ADODB.Parameter prm;
  7.  
  8.             con = null;
  9.             con = new ADODB.Connection();
  10.             con.Provider = "SQLOLEDB.1";
  11.             con.ConnectionString = "Description=MyDB;IntegratedSecurity=SSPI;Trusted_C  onnection=Yes;APP=MyApp;WSID=MyServer;DATABASE=MyD  B";
  12.             con.Open(con.ConnectionString , null, null, 0);
  13.  
  14.             com = null;
  15.             com = new ADODB.Command();
  16.             com.CommandText = "MyStoredProc";
  17.             com.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc;
  18.             com.NamedParameters = true;
  19.             com.Prepared = false;
  20.             com.Name = ("MyStoredProc" + System.DateTime.Now.ToString("yyyyMMddHHmmssffff"));
  21.  
  22.             prm = null;
  23.  
  24.            
  25.             prm = com.CreateParameter("@LocationNameIn", DataTypeEnum.adVarChar, ParameterDirectionEnum.adParamInput, 80, Convert.ToString("London"));
  26.             com.Parameters.Append(prm);
  27.             prm.Value = Convert.ToString("London");
  28.             prm = null;
  29.  
  30.              prm = com.CreateParameter("@Time", DataTypeEnum.adDBTimeStamp, ParameterDirectionEnum.adParamInput, 0, Convert.ToDateTime("01/12/2011 00:20"));
  31.             com.Parameters.Append(prm);
  32.             prm = null;
  33.  
  34.             prm = com.CreateParameter("@Param3", DataTypeEnum.adDouble, ParameterDirectionEnum.adParamInput, 0, 1000.0);
  35.             com.Parameters.Append(prm);
  36.             prm = null;
  37.  
  38.             prm = com.CreateParameter("@Param4", DataTypeEnum.adDouble, ParameterDirectionEnum.adParamInput, 0, -999);
  39.             com.Parameters.Append(prm);
  40.             prm = null;
  41.  
  42.             prm = com.CreateParameter("@Param5", DataTypeEnum.adDouble, ParameterDirectionEnum.adParamInput, 0, 245.9);
  43.             com.Parameters.Append(prm);
  44.             prm = null;
  45.  
  46.             prm = com.CreateParameter("@Param6", DataTypeEnum.adDouble, ParameterDirectionEnum.adParamInput, 0, -999);
  47.             com.Parameters.Append(prm);
  48.  
  49.             prm = null;
  50.  
  51.             prm = com.CreateParameter("@Param7", DataTypeEnum.adVarChar, ParameterDirectionEnum.adParamInput, 20, "South");
  52.             com.Parameters.Append(prm);
  53.             prm = null;
  54.  
  55.             prm = com.CreateParameter("@Param8", DataTypeEnum.adDouble , ParameterDirectionEnum.adParamInput, 0, 0);
  56.             com.Parameters.Append(prm);
  57.             prm = null;
  58.  
  59.             prm = com.CreateParameter("@Param9", DataTypeEnum.adVarChar, ParameterDirectionEnum.adParamInput, 120, "BlahdiblahPC");
  60.             com.Parameters.Append(prm);
  61.             prm = null;
  62.  
  63.  
  64.             com.ActiveConnection = con;
  65.             object oRA = new object();
  66.             object oPRM = new object();
  67.             rst = com.Execute(out oRA, ref oPRM, (int)ExecuteOptionEnum.adExecuteRecord);
  68.  
  69.         }


When i do a stack trace on the database i find the following is being submitted:

Quote:
exec MyStoredProc @LocationNameIn='System.Object',@Time='2011-12-01 00:20:00',@Param3=1000,@Param4=-999,@Param5=245.90000000000001,@Param6=-999,@Param7='South',@Param8=0,@Param9='BlahdiblahP C'


I can't figure out why it is inserting 'System.Object' instead of 'London'. I will be very grateful for any help received.

Reply With Quote
  #2  
Old December 20th, 2011, 03:09 AM
confuseddotcom confuseddotcom is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2011
Posts: 2 confuseddotcom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 7 m 49 sec
Reputation Power: 0
it turns out i was overriding the first parameter in the line before command.execute. I added the following in it's place:

Code:
object prm = com.Parameters[0].Value;

Reply With Quote
  #3  
Old November 7th, 2014, 11:17 PM
kathi kathi is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2014
Posts: 1 kathi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 42 sec
Reputation Power: 0
I am creating a scheduled service application.
One of the applications returns a message box when completed.
I need to simulate a user clicking ok or pressing enter or space to get rid of the message box
can anyone help us??????????????????????????


____________

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgramming.NET Development > Trouble using ADODB to call a stored proc


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap