From: Joe Cool on
I am trying to run a query from a C#.NET application using the
standard SqlClient connected to a SQL2005 database. Basically the
query is:

select count(*) from table1 where column1 is not null or column1 > 0

table1 exists and contains a column named column1. column1 is an int
datatype and allow nulls. If I run the query from a query window in
the SQL Server Management Studio, it runs just fine.

However if I run it from the C#.NET app, the
ColumnIndexOutOfRangeException is being thrown. The message text is
"index was outside the bounds of the array".

Any ideas?
From: Joe Cool on
On Jul 23, 6:25 pm, Joe Cool <joecool1...(a)live.com> wrote:
> I am trying to run a query from a C#.NET application using the
> standard SqlClient connected to a SQL2005 database. Basically the
> query is:
>
> select count(*) from table1 where column1 is not null or column1 > 0
>
> table1 exists and contains a column named column1. column1 is an int
> datatype and allow nulls. If I run the query from a query window in
> the SQL Server Management Studio, it runs just fine.
>
> However if I run it from the C#.NET app, the
> ColumnIndexOutOfRangeException is being thrown. The message text is
> "index was outside the bounds of the array".
>
> Any ideas?

Well, now I am not sure if this a problem or not. Actually, I was
seeing this in a VB.NET program that I am converting to C#.NET. This
app produces a report based on the content of a database. I wanted to
generate the report with the VB version so I could make sure the
output of the C# version was identical. I now have the C# version in
testing mode and I am not getting this error with it.

Go figure.
From: Erland Sommarskog on
Joe Cool (joecool1969(a)live.com) writes:
> On Jul 23, 6:25�pm, Joe Cool <joecool1...(a)live.com> wrote:
>> I am trying to run a query from a C#.NET application using the
>> standard SqlClient connected to a SQL2005 database. Basically the
>> query is:
>>
>> select count(*) from table1 where column1 is not null or column1 > 0
>>
>> table1 exists and contains a column named column1. column1 is an int
>> datatype and allow nulls. If I run the query from a query window in
>> the SQL Server Management Studio, it runs just fine.
>>
>> However if I run it from the C#.NET app, the
>> ColumnIndexOutOfRangeException is being thrown. The message text is
>> "index was outside the bounds of the array".
>>
>> Any ideas?
>
> Well, now I am not sure if this a problem or not. Actually, I was
> seeing this in a VB.NET program that I am converting to C#.NET. This
> app produces a report based on the content of a database. I wanted to
> generate the report with the VB version so I could make sure the
> output of the C# version was identical. I now have the C# version in
> testing mode and I am not getting this error with it.

Whatever, the error is a VB error, and I don't think you will get
much help with it in an SQL newsgroup. Particularly if you don't
include the VB code.


--
Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx