Click here to Skip to main content
15,890,897 members
Home / Discussions / Database
   

Database

 
AnswerRe: SQL where Clause help needed Pin
Blue_Boy9-Nov-10 23:31
Blue_Boy9-Nov-10 23:31 
AnswerRe: SQL where Clause help needed Pin
Scubapro10-Nov-10 1:07
Scubapro10-Nov-10 1:07 
AnswerRe: SQL where Clause help needed Pin
Chris Meech10-Nov-10 6:51
Chris Meech10-Nov-10 6:51 
QuestionBasic Question from a newbie Pin
JohnnyG9-Nov-10 14:49
JohnnyG9-Nov-10 14:49 
AnswerRe: Basic Question from a newbie PinPopular
Jörgen Andersson9-Nov-10 23:54
professionalJörgen Andersson9-Nov-10 23:54 
GeneralRe: Basic Question from a newbie Pin
PIEBALDconsult10-Nov-10 2:10
mvePIEBALDconsult10-Nov-10 2:10 
GeneralRe: Basic Question from a newbie Pin
JohnnyG10-Nov-10 2:36
JohnnyG10-Nov-10 2:36 
QuestionGetting InvalidCastException using VS2005 TableAdapter generator to call a stored procedure Pin
Brian C Hart8-Nov-10 18:49
professionalBrian C Hart8-Nov-10 18:49 
I have a stored procedure defined thusly -- actual variable, database, and table names have been altered for NDA reasons:

CREATE PROCEDURE [dbo].[CountUniqueBirthdays] 
	@PersonID bigint
AS
 

BEGIN

SET NOCOUNT ON;
    
DECLARE @CalendarDaysToSearch int

SET @CalendarDaysToSearch = 90 


	SELECT  COUNT(DISTINCT o.Birthdays) 
		FROM
			[MYDATABASE].[dbo].[PersonInfo] n,
			[MYDATABASE].[dbo].[PersonInfo] o
		WHERE
			n.PersonID = @PersonID AND
			--n.PersonID <> o.PersonID AND

			-- all leads with...
			n.KeyPerson=o.KeyPersonAND
			
			-- within X days of current lead
			o.CalendarDate between dateadd(dd, (-1 * @CalendarDaysToSearch ), n.CalendarDate ) and dateadd(dd, 0, n.CalendarDate ) 

END


For the sake of argument, assume this stored procedure is written correctly and is known to work. Now, I opened up VS2005 (my boss wants me to use it) and in the Data Sources window, I did the whole Add New Data Source/Data Source Configuration Wizard yada yada and added a TableAdapter to my DataSet for PersonInfo (not the real table name again).

I configured the TableAdapterto do a SELECT PersonId FROM PersonInfo and then also to call the Stored Procedure, CountUniqueBirthdays, above. ok, so i write the code to grab the records containing only the PersonIDcolumn and then I iterate over the column, passing each ID into the stored procedure one by one to check if the number of distinct persons with birthdays in a certain 90-day period is bigger than 1 -- AND DON'T ASK ME WHY DID I NOT JUST USE A CURSOR, CURSORS ARE SLOW AND WE HATE THEM, as below.

You know how you can open .xsd files in the Dataset Designer in VS2005? Well, I did, right-clicked the PersonInfo TableAdapter, clicked Add > New Query... and in the Add New Query Wizard I picked Existing stored procedure, and then configured CountUniqueBirthdays as the stored procedure to use.

            <br />
try<br />
{<br />
                Console.WriteLine("Querying the MYDATABASE.dbo.PersonInfo table...Please wait.");<br />
                MYDATABASEDataSetTableAdapters.PersonInfoTableAdapter adapter =<br />
                    new MYDATABASEDataSetTableAdapters.PersonInfoTableAdapter();<br />
                MYDATABASEDataSet.PersonInfoDataTable table =<br />
                    adapter.GetData();<br />
                Console.WriteLine("Finished getting data.");<br />
<br />
                Console.WriteLine("Running the CountUniqueBirthdays stored procdure.  Searching for return values > 1...");<br />
                foreach (MYDATABASEDataSet.PersonInfoRow row in table.Rows)<br />
                {<br />
                    // Get the LeadId value<br />
                    long? personID = row.PersonId;<br />
                    if (!personID.HasValue)<br />
                        continue;<br />
<br />
                    Console.WriteLine("Checking output of CountUniqueBirthdays for PersonId = {0}...", leadID);<br />
<br />
                    // Pass the LeadId to the stored procedure<br />
                    long? value = adapter.CountUniqueBirthdays(leadID);<br />
                    if (value.HasValue) {<br />
                        if (value.Value > 1)<br />
                        {<br />
                            Console.WriteLine("Value > 1 found for return from LQSCountVendor190Days...for <br />
                              leadId = {0}",leadID);<br />
                            break;<br />
                        }<br />
                    }<br />
                }<br />
            }<br />
            catch (Exception e)<br />
            {<br />
                Console.WriteLine(e.Message);<br />
                return;<br />
            }


The output from the console app is:

<br />
Querying the MYDATABASE.dbo.PersonInfo table...Please wait.<br />
Finished getting data.<br />
Running the CountUniqueBirthdays stored procdure.  Searching for return values > 1...<br />
Checking output of CountUniqueBirthdays for PersonId = 8752702...<br />
Specified cast is not valid.


Why? I followed what the IntelliSense had me do when I was typing in the stored procedure call! I don't get it, can somebody please help a newbie at Database programming?

Brian
AnswerRe: Getting InvalidCastException using VS2005 TableAdapter generator to call a stored procedure Pin
John Gathogo8-Nov-10 19:05
John Gathogo8-Nov-10 19:05 
GeneralRe: Getting InvalidCastException using VS2005 TableAdapter generator to call a stored procedure Pin
Brian C Hart8-Nov-10 20:06
professionalBrian C Hart8-Nov-10 20:06 
QuestionOracle ALL_TAB_COLUMNS Pin
Mycroft Holmes7-Nov-10 13:33
professionalMycroft Holmes7-Nov-10 13:33 
AnswerRe: Oracle ALL_TAB_COLUMNS Pin
Jörgen Andersson7-Nov-10 20:20
professionalJörgen Andersson7-Nov-10 20:20 
GeneralRe: Oracle ALL_TAB_COLUMNS Pin
Mycroft Holmes7-Nov-10 21:13
professionalMycroft Holmes7-Nov-10 21:13 
GeneralRe: Oracle ALL_TAB_COLUMNS [modified] Pin
Jörgen Andersson7-Nov-10 21:43
professionalJörgen Andersson7-Nov-10 21:43 
GeneralRe: Oracle ALL_TAB_COLUMNS Pin
Mycroft Holmes7-Nov-10 22:26
professionalMycroft Holmes7-Nov-10 22:26 
GeneralRe: Oracle ALL_TAB_COLUMNS Pin
Jörgen Andersson7-Nov-10 23:05
professionalJörgen Andersson7-Nov-10 23:05 
Questionhow to insert variable values in SQL server using INSERT INTO statement? Pin
MahaKh4-Nov-10 20:41
MahaKh4-Nov-10 20:41 
AnswerRe: how to insert variable values in SQL server using INSERT INTO statement? Pin
RaviRanjanKr5-Nov-10 6:32
professionalRaviRanjanKr5-Nov-10 6:32 
AnswerRe: how to insert variable values in SQL server using INSERT INTO statement? Pin
PIEBALDconsult6-Nov-10 3:59
mvePIEBALDconsult6-Nov-10 3:59 
GeneralRe: how to insert variable values in SQL server using INSERT INTO statement? Pin
MahaKh6-Nov-10 23:49
MahaKh6-Nov-10 23:49 
GeneralRe: how to insert variable values in SQL server using INSERT INTO statement? Pin
PIEBALDconsult7-Nov-10 3:12
mvePIEBALDconsult7-Nov-10 3:12 
GeneralRe: how to insert variable values in SQL server using INSERT INTO statement? Pin
RaviRanjanKr8-Nov-10 7:12
professionalRaviRanjanKr8-Nov-10 7:12 
GeneralRe: how to insert variable values in SQL server using INSERT INTO statement? Pin
MahaKh9-Nov-10 7:11
MahaKh9-Nov-10 7:11 
GeneralRe: how to insert variable values in SQL server using INSERT INTO statement? Pin
MDNadeemAkhter8-Nov-10 16:55
MDNadeemAkhter8-Nov-10 16:55 
GeneralRe: how to insert variable values in SQL server using INSERT INTO statement? Pin
Pete O'Hanlon9-Nov-10 9:36
mvePete O'Hanlon9-Nov-10 9:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.