Click here to Skip to main content
15,887,856 members
Home / Discussions / Database
   

Database

 
GeneralCrystal Report Threw internal Exception Pin
agmb28-Jun-05 3:37
agmb28-Jun-05 3:37 
GeneralForce SELECT to return a single row Pin
BinaryHead28-Jun-05 0:59
BinaryHead28-Jun-05 0:59 
GeneralRe: Force SELECT to return a single row Pin
Colin Angus Mackay28-Jun-05 1:17
Colin Angus Mackay28-Jun-05 1:17 
GeneralRe: Force SELECT to return a single row Pin
P A N K A J28-Jun-05 17:48
P A N K A J28-Jun-05 17:48 
GeneralGet file name using SQL Pin
Wilbur J. Pereira28-Jun-05 0:16
Wilbur J. Pereira28-Jun-05 0:16 
QuestionSpecified cast is not valid? Pin
WetRivrRat27-Jun-05 13:36
WetRivrRat27-Jun-05 13:36 
AnswerRe: Specified cast is not valid? Pin
Christian Graus27-Jun-05 19:58
protectorChristian Graus27-Jun-05 19:58 
GeneralRe: Specified cast is not valid? Pin
WetRivrRat28-Jun-05 13:04
WetRivrRat28-Jun-05 13:04 
ok,
so I've changed it a small bit, checked it, done the stack trace, and it is still failing,
but the catch -- e.Message is giving the following: incorrect syntax near 'transaction_ table'

and the catch -- e.StackTrace is giving the following:
at system.data.sqlclient.sqlcommand.executereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream)
at system.data.sqlclient.sqlcommand.executereader()
at reportorders.report.main(string[] args) in c:\documents and settings.....(it list the filename)report.cs:line28
Press any key to continue

line 34 is not the FROM Transaction_Table statement line...but rather the dataReader execution statement.
I've double checked query in query analizer and it works Confused | :confused:
what am I missing here? can I not do an aggregate function with the dataReader? Frown | :(

I will enclose the code again, in its modified version... (again, i'm using the C# console app template in vs.net 2003)

Also, you can comment / uncomment out the "Sequence_Number" from the query and from the
int Sequence_Number = dataReader.GetInt32(0); parts, as that is the primary key
Thanks, again...

using System;
using System.Data.SqlClient;

namespace ReportOrders
{
	
	class Report
	{
	
	[STAThread]
	static void Main(string[] args)
	{
	
	try
	{
	SqlConnection dataConnection = new SqlConnection();
	dataConnection.ConnectionString = "user ID=blah;pwd=BLAH;Initial Catalog=sellmdat2kSQL;Data Source=localhost";
	dataConnection.Open();
	Console.WriteLine("Please enter a Location ID (4 characters): ");
	string Location_ID = Console.ReadLine();
	Console.WriteLine("Please enter a Shift Number (4 characters): ");
	string Shift_Number = Console.ReadLine();
	SqlCommand dataCommand = new SqlCommand();
	dataCommand.Connection = dataConnection;
	dataCommand.CommandText = "SELECT sum (Amount)as Amount";
        //dataCommand.CommandText = "SELECT Sequence_Number, sum (Amount)as Amount";
	dataCommand.CommandText += "FROM transaction_table WHERE Location_id ='" + Location_ID + "' and Shift_Number='" + Shift_Number + "'";
	Console.WriteLine("About to execute: " + dataCommand.CommandText);
	SqlDataReader dataReader = dataCommand.ExecuteReader();
	while (dataReader.Read())
	{
	int Sequence_Number = dataReader.GetInt32(0);
	if (dataReader.IsDBNull(2))
	{
	Console.WriteLine("Shift Number {0} not yet closed\n\n", Shift_Number);
	}
	else
	{
	string Amount = dataReader.GetString(0);
	Console.WriteLine("Value {0}\nAdded Since Last Shift ", Amount );
	}
	}
	dataReader.Close();
	dataConnection.Close();
	}
	catch(Exception e)
	{
	Console.WriteLine("An error occurred accessing the database: " + e.StackTrace);
	}
	}
	}
}




Dim Beautiful As String
Beautiful = "ignorant"
Label1.Text = "The world is full of " & Beautiful & " people."


Why is common sense such an un-common comodity?
GeneralRe: Specified cast is not valid? Pin
Christian Graus28-Jun-05 13:18
protectorChristian Graus28-Jun-05 13:18 
GeneralRe: Specified cast is not valid? Pin
WetRivrRat28-Jun-05 13:33
WetRivrRat28-Jun-05 13:33 
GeneralRe: Specified cast is not valid? Pin
WetRivrRat28-Jun-05 14:32
WetRivrRat28-Jun-05 14:32 
GeneralRe: Specified cast is not valid? Pin
Christian Graus28-Jun-05 14:55
protectorChristian Graus28-Jun-05 14:55 
GeneralRe: Specified cast is not valid? Pin
WetRivrRat28-Jun-05 15:52
WetRivrRat28-Jun-05 15:52 
GeneralRe: Specified cast is not valid? Pin
Christian Graus28-Jun-05 17:07
protectorChristian Graus28-Jun-05 17:07 
GeneralRe: Specified cast is not valid? Pin
WetRivrRat28-Jun-05 17:13
WetRivrRat28-Jun-05 17:13 
GeneralRe: Specified cast is not valid? Pin
WetRivrRat28-Jun-05 17:14
WetRivrRat28-Jun-05 17:14 
GeneralRe: Specified cast is not valid? Pin
Christian Graus28-Jun-05 17:47
protectorChristian Graus28-Jun-05 17:47 
GeneralRe: Specified cast is not valid? Pin
WetRivrRat28-Jun-05 18:11
WetRivrRat28-Jun-05 18:11 
GeneralRe: Specified cast is not valid? Pin
Christian Graus28-Jun-05 18:27
protectorChristian Graus28-Jun-05 18:27 
GeneralRe: Specified cast is not valid? Pin
WetRivrRat28-Jun-05 18:51
WetRivrRat28-Jun-05 18:51 
GeneralRe: Specified cast is not valid? Pin
Christian Graus28-Jun-05 18:59
protectorChristian Graus28-Jun-05 18:59 
GeneralRe: Specified cast is not valid? Pin
WetRivrRat29-Jun-05 13:45
WetRivrRat29-Jun-05 13:45 
GeneralImporting a CSV File Into Oracle Pin
wayevans27-Jun-05 10:38
wayevans27-Jun-05 10:38 
GeneralADO connections Pin
HahnTech27-Jun-05 9:07
HahnTech27-Jun-05 9:07 
GeneralPlease give me an advive Pin
Blue_Skye27-Jun-05 8:00
Blue_Skye27-Jun-05 8:00 

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.