Hello,
[color=Black]
I am trying to learn how to programatically create a connection to a sql server database on my local machine. My server name is DAEDULUS and database name is RezSys. When ever I try to extract data from the table Hotel it gives me the following error:[/color]
[color=Green]
Connection Sucessfull
Unhandled Exception: System.IndexOutOfRangeException: Index was outside the boun
ds of the array.
at System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i, Boolean setTimeout
)
at System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i)
at main(String[] args) in c:documents and settingsjutmy documentsvisual s
tudio 2005projects est est est.cpp:line 28
at mainCRTStartupStrArray(String[] arguments) in f:
tmvctoolscrt_bldself_
x86crtsrcmcrtexe.cpp:line 324
Press any key to continue . . .
[/color]
[color=Black]I know I should have a try catch block but that will come after.
My source code is below:[/color]
[color=Green]
#include "stdafx.h"
using namespace System;
using namespace System::Data::SqlClient;
int main(array ^args)
{
Console::WriteLine(L"Hello World");
SqlCommand^ comm;
SqlConnection^ myCon = gcnew SqlConnection("server=DAEDULUS;Trusted_Connection=yes;Initial Catalog=RezSys;");
myCon->Open();
comm = gcnew SqlCommand("select [RoomType] from [Hotel]",myCon);
if(comm->ExecuteNonQuery())
{
Console::WriteLine(L"Connection Sucessfull");
}
SqlDataReader^ reader;
reader = comm->ExecuteReader();
while(reader->Read())
{
Console::Write(reader->GetInt32(1));
}
myCon->Close();
return 0;
}
[/color]
[color=Black]
I am not sure what I am doing wrong any help would be appreciated.
Sincerely,
Jut26
[/color]
Comments
[color=Green]
RoomNum int Unchecked
RoomType nchar(25) Unchecked
Arrival smalldatetime Checked
Departure smalldatetime Checked
Availibility bit Unchecked
[/color]
: Hello,
: [color=Black]
: I am trying to learn how to programatically create a connection to
: a sql server database on my local machine. My server name is
: DAEDULUS and database name is RezSys. When ever I try to extract
: data from the table Hotel it gives me the following error:[/color]
: [color=Green]
: Connection Sucessfull
:
: Unhandled Exception: System.IndexOutOfRangeException: Index was
: outside the boun
: ds of the array.
: at System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i,
: Boolean setTimeout
: )
: at System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i)
: at main(String[] args) in c:documents and settingsjutmy
: documentsvisual s
: tudio 2005projects est est est.cpp:line 28
: at mainCRTStartupStrArray(String[] arguments) in
: f:
tmvctoolscrt_bldself_
: x86crtsrcmcrtexe.cpp:line 324
: Press any key to continue . . .
: [/color]
: [color=Black]I know I should have a try catch block but that will
: come after.
:
: My source code is below:[/color]
: [color=Green]
: #include "stdafx.h"
:
: using namespace System;
: using namespace System::Data::SqlClient;
:
: int main(array ^args)
: {
:
:
: Console::WriteLine(L"Hello World");
:
: SqlCommand^ comm;
:
: SqlConnection^ myCon = gcnew
: SqlConnection("server=DAEDULUS;Trusted_Connection=yes;Initial
: Catalog=RezSys;");
: myCon->Open();
: comm = gcnew SqlCommand("select [RoomType] from
: [Hotel]",myCon);
: if(comm->ExecuteNonQuery())
: {
: Console::WriteLine(L"Connection Sucessfull");
: }
:
: SqlDataReader^ reader;
: reader = comm->ExecuteReader();
: while(reader->Read())
: {
: Console::Write(reader->GetInt32(1));
: }
: myCon->Close();
:
: return 0;
: }
: [/color]
:
: [color=Black]
: I am not sure what I am doing wrong any help would be appreciated.
:
:
: Sincerely,
: Jut26
: [/color]
:
: Hello,
: [color=Black]
: I am trying to learn how to programatically create a connection to
: a sql server database on my local machine. My server name is
: DAEDULUS and database name is RezSys. When ever I try to extract
: data from the table Hotel it gives me the following error:[/color]
: [color=Green]
: Connection Sucessfull
:
: Unhandled Exception: System.IndexOutOfRangeException: Index was
: outside the boun
: ds of the array.
: at System.Data.SqlClient.SqlDataReader.ReadColumn(Int32 i,
: Boolean setTimeout
: )
: at System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i)
: at main(String[] args) in c:documents and settingsjutmy
: documentsvisual s
: tudio 2005projects est est est.cpp:line 28
: at mainCRTStartupStrArray(String[] arguments) in
: f:
tmvctoolscrt_bldself_
: x86crtsrcmcrtexe.cpp:line 324
: Press any key to continue . . .
: [/color]
: [color=Black]I know I should have a try catch block but that will
: come after.
:
: My source code is below:[/color]
: [color=Green]
: #include "stdafx.h"
:
: using namespace System;
: using namespace System::Data::SqlClient;
:
: int main(array ^args)
: {
:
:
: Console::WriteLine(L"Hello World");
:
: SqlCommand^ comm;
:
: SqlConnection^ myCon = gcnew
: SqlConnection("server=DAEDULUS;Trusted_Connection=yes;Initial
: Catalog=RezSys;");
: myCon->Open();
: comm = gcnew SqlCommand("select [RoomType] from
: [Hotel]",myCon);
: if(comm->ExecuteNonQuery())
: {
: Console::WriteLine(L"Connection Sucessfull");
: }
:
: SqlDataReader^ reader;
: reader = comm->ExecuteReader();
: while(reader->Read())
: {
: Console::Write(reader->GetInt32(1));
: }
: myCon->Close();
:
: return 0;
: }
: [/color]
:
: [color=Black]
: I am not sure what I am doing wrong any help would be appreciated.
:
:
: Sincerely,
: Jut26
: [/color]
: