Showing posts with label systemindexoutofrangeexception. Show all posts
Showing posts with label systemindexoutofrangeexception. Show all posts

Saturday, March 31, 2012

System.IndexOutOfRangeException

I have the following code...

Public Sub SelectPieceByProductID()

Try

Dim arParams(0) As SqlParameter

arParams(0) = New SqlParameter("@dotnet.itags.org.lProductID", lProductID)

Dim oDR As SqlDataReader =
oData.ExecuteReader(sConnectionString, CommandType.StoredProcedure,
"spSelectPieceByProductID", arParams)

If oDR.HasRows Then
Do While oDR.Read()
sPieceNumber = CType(oDR.Item("PieceNumber"),
String)
lMetalID = CType(oDR.Item("MetalID"), Long)
lTotalCount = CType(oDR.Item("TotalCount"), Long)
dTotalWeight = CType(oDR.Item("TotalWeight"),
Double)
--> lNonCenterCount =
CType(oDR.Item("NonCenterCount "), Long)
dNonCenterWeight =
CType(oDR.Item("NonCenterWeight"), Double)
dPrice = CType(oDR.Item("Price"), Double)
lMarkup = CType(oDR.Item("Markup"), Long)
bActive = CType(oDR.Item("Active"), Boolean)
bDeleted = CType(oDR.Item("Deleted"), Boolean)
Loop
End If

oDR.Close()

oDR = Nothing
oData = Nothing

Catch ex As Exception

End Try

End Sub

I am getting an "System.IndexOutOfRangeException" exception on the
marked line. All values prior to this line are being set correctly.
Anyone see the issue here? I run the query in query analyzer with the
appropriate id and it works fine.

I'm clueless.

Thanks.It seems that the NonCenterCount column does not exist. Perhaps the column
name is mispelled either here, or in the table definition.

"Ratman" <jake@.attis.org> wrote in message
news:df331d52.0406210944.2c966e3c@.posting.google.c om...
> I have the following code...
> Public Sub SelectPieceByProductID()
> Try
> Dim arParams(0) As SqlParameter
> arParams(0) = New SqlParameter("@.lProductID", lProductID)
> Dim oDR As SqlDataReader =
> oData.ExecuteReader(sConnectionString, CommandType.StoredProcedure,
> "spSelectPieceByProductID", arParams)
> If oDR.HasRows Then
> Do While oDR.Read()
> sPieceNumber = CType(oDR.Item("PieceNumber"),
> String)
> lMetalID = CType(oDR.Item("MetalID"), Long)
> lTotalCount = CType(oDR.Item("TotalCount"), Long)
> dTotalWeight = CType(oDR.Item("TotalWeight"),
> Double)
> --> lNonCenterCount =
> CType(oDR.Item("NonCenterCount "), Long)
> dNonCenterWeight =
> CType(oDR.Item("NonCenterWeight"), Double)
> dPrice = CType(oDR.Item("Price"), Double)
> lMarkup = CType(oDR.Item("Markup"), Long)
> bActive = CType(oDR.Item("Active"), Boolean)
> bDeleted = CType(oDR.Item("Deleted"), Boolean)
> Loop
> End If
> oDR.Close()
> oDR = Nothing
> oData = Nothing
> Catch ex As Exception
> End Try
> End Sub
> I am getting an "System.IndexOutOfRangeException" exception on the
> marked line. All values prior to this line are being set correctly.
> Anyone see the issue here? I run the query in query analyzer with the
> appropriate id and it works fine.
> I'm clueless.
> Thanks.

System.IndexOutOfRangeException

I have the following code...
Public Sub SelectPieceByProductID()
Try
Dim arParams(0) As SqlParameter
arParams(0) = New SqlParameter("@dotnet.itags.org.lProductID", lProductID)
Dim oDR As SqlDataReader =
oData.ExecuteReader(sConnectionString, CommandType.StoredProcedure,
"spSelectPieceByProductID", arParams)
If oDR.HasRows Then
Do While oDR.Read()
sPieceNumber = CType(oDR.Item("PieceNumber"),
String)
lMetalID = CType(oDR.Item("MetalID"), Long)
lTotalCount = CType(oDR.Item("TotalCount"), Long)
dTotalWeight = CType(oDR.Item("TotalWeight"),
Double)
--> lNonCenterCount =
CType(oDR.Item("NonCenterCount "), Long)
dNonCenterWeight =
CType(oDR.Item("NonCenterWeight"), Double)
dPrice = CType(oDR.Item("Price"), Double)
lMarkup = CType(oDR.Item("Markup"), Long)
bActive = CType(oDR.Item("Active"), Boolean)
bDeleted = CType(oDR.Item("Deleted"), Boolean)
Loop
End If
oDR.Close()
oDR = Nothing
oData = Nothing
Catch ex As Exception
End Try
End Sub
I am getting an "System.IndexOutOfRangeException" exception on the
marked line. All values prior to this line are being set correctly.
Anyone see the issue here? I run the query in query analyzer with the
appropriate id and it works fine.
I'm clueless.
Thanks.It seems that the NonCenterCount column does not exist. Perhaps the column
name is mispelled either here, or in the table definition.
"Ratman" <jake@.attis.org> wrote in message
news:df331d52.0406210944.2c966e3c@.posting.google.com...
> I have the following code...
> Public Sub SelectPieceByProductID()
> Try
> Dim arParams(0) As SqlParameter
> arParams(0) = New SqlParameter("@.lProductID", lProductID)
> Dim oDR As SqlDataReader =
> oData.ExecuteReader(sConnectionString, CommandType.StoredProcedure,
> "spSelectPieceByProductID", arParams)
> If oDR.HasRows Then
> Do While oDR.Read()
> sPieceNumber = CType(oDR.Item("PieceNumber"),
> String)
> lMetalID = CType(oDR.Item("MetalID"), Long)
> lTotalCount = CType(oDR.Item("TotalCount"), Long)
> dTotalWeight = CType(oDR.Item("TotalWeight"),
> Double)
> --> lNonCenterCount =
> CType(oDR.Item("NonCenterCount "), Long)
> dNonCenterWeight =
> CType(oDR.Item("NonCenterWeight"), Double)
> dPrice = CType(oDR.Item("Price"), Double)
> lMarkup = CType(oDR.Item("Markup"), Long)
> bActive = CType(oDR.Item("Active"), Boolean)
> bDeleted = CType(oDR.Item("Deleted"), Boolean)
> Loop
> End If
> oDR.Close()
> oDR = Nothing
> oData = Nothing
> Catch ex As Exception
> End Try
> End Sub
> I am getting an "System.IndexOutOfRangeException" exception on the
> marked line. All values prior to this line are being set correctly.
> Anyone see the issue here? I run the query in query analyzer with the
> appropriate id and it works fine.
> I'm clueless.
> Thanks.

System.IndexOutOfRangeException - DDL Binding

Hey

Im trying to populate a dropdown list for a holiday package selection
I want the drop down list to produce a list something like this:

Australia
- Sydney
- Gold Coast
- Canberra
Asia
- China
- Japan
etc etc

There seems to be something wrong with setting a string to a datafield
Particularly the line of code:

strDestination = myDataReader("Destinaton")

This is the error I get:

Exception Details: System.IndexOutOfRangeException: Destinaton

Here is the code:

Sub PopulateDestinationDDL()
Dim dlConnection as New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=c:\digitise\hot\database\hot80.mdb")
Dim dlCommandText as String = "SELECT DISTINCT Region, Destination FROM Deal ORDER BY Destination"
Dim dlCommand as New OleDbCommand(dlCommandText, dlConnection)

dlConnection.Open()
Dim myDataReader as OleDbDataReader = dlCommand.ExecuteReader()
While myDataReader.Read
Dim strDestination as String
If Not myDataReader("Destination") = strDestination
dlDestination.Items.Add(New ListItem(myDataReader("Destination"), myDataReader("Destination")))
End If
dlDestination.Items.Add(New ListItem("- " & myDataReader("Region"), myDataReader("Region")))
strDestination = myDataReader("Destinaton")
End While
dlConnection.Close()
End Sub 'PopulateDestinationDDL

Cheers
CharlesI think you mean to say Destination, rather than Destinaton. ;)
Yeah I accually just realised that as soon as I posted it. ;)
Silly me.

But I have another thing I am confused about....

With this drop down list I want it to autopost back and then change its items
I can't seem to get the drop down list to lose all of its items before repopulating it.

Cheers
Charles

Are you doing your databind on every postback? Are you calling PopulateDestinationDDL from your Page_Load sub procedure? Try wrapping it inside of aIf Not Page.IsPostback code block.

Please show your Page_Load code if you still want help.

Here is all the code I have made:


Sub Page_Load(sender as Object, e as EventArgs)
If Not Page.IsPostBack Then
PopulateDestinationDDL()
End If
End Sub 'Page_Load

Sub PopulateDestinationDDL()
'dlDestination = New DropDownList()
Dim dlCommandText as String
If rdHolAir.SelectedItem.Value = "hol" Then
dlCommandText = "SELECT DISTINCT Region, Destination FROM Deal WHERE DealCode NOT LIKE '%HOT%' ORDER BY Destination"
Else
dlCommandText = "SELECT DISTINCT Region, Destination FROM Deal WHERE DealCode LIKE '%HOT%' ORDER BY Destination"
End If

Dim dlConnection as New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0; Data Source=lala.mdb")
Dim dlCommand as New OleDbCommand(dlCommandText, dlConnection)

dlConnection.Open()
Dim myDataReader as OleDbDataReader = dlCommand.ExecuteReader()
While myDataReader.Read
Dim strDestination as String
If Not myDataReader("Destination") = strDestination
dlDestination.Items.Add(New ListItem(myDataReader("Destination"), myDataReader("Destination")))
End If
dlDestination.Items.Add(New ListItem("- " & myDataReader("Region"), myDataReader("Region")))
strDestination = myDataReader("Destination")
End While
dlConnection.Close()
End Sub 'PopulateDestinationDDL

Sub rdHolAir_Change(sender as Object, e as EventArgs)
PopulateDestinationDDL()
End Sub 'rdHolAir_Change


Right - I think viewstate is automatically maintaining the values in your DropDownList. Try using the Items.Clear() method of your DDL before calling your PopulateDestinationDDL procedure.
Wait a second, you'll need to get the SelectedItem.Valuebefore clearing the items...
Shot
Works like a charm

Cheers
Charles

System.IndexOutOfRangeException

I'm seeing the above error message appear on a web form. All the formcode-behind does is grab data from a SQL Server db (2005 Beta) andwrite it out in specfied controls.
The line that throws up the error is the following:
<code>
Line 150: txtCoDeath1a.Text = dtr("COD1a")
</code>
'Dtr' is simply a datareader that has been initialised previously. Iknow I should be checking for nulls in the db, but that isn't theproblem in this instant as the record I'm grabbing does have data forthe field 'COD1a'. It's of type nvarchar, length 150.
I've googled this error and have not found anything that seems directly relevant.
I'm using VB.
Any help much appreciated.

try putting this before your code

if dtr.Read then
dtr("COD1a")
end if


Sorry Chris, I should've posted more of my code.
I already have those lines in the code.
Any other ideas?

Try this

if not System.DBNull(dtr("COD1a")) then

txtCoDeath1a.Text = dtr("COD1a")

end if

Could you post more of your code? Are results coming back from the database? Is there a field called COD1a?


Thanks for the help guys, but I've located the source of theproblem. Very simple; I'd misnamed 'Cod1a'. Its actually 'CodIa'. Spotthe difference? Neither did I for a while!
<Sheepish> Sorry and thanks again.

System.IndexOutOfRangeException

Hello,

I have the following code where all the used variable are declared to their respective types:

insertSql = "SELECT Max([Customer ID]) AS CustID FROM [Registration Info]"
objCommand = New OleDbCommand(insertSql, objConn)
objConn.Open()
objDR = objCommand.ExecuteReader()

While objDR.Read()
CustID=objDR("Cust ID") '********** (1.)
End While

I am getting an error on (1.). its says "System.IndexOutOfRangeException: Cust ID" why is this happening? Can comeone help me whith this problem?

Thanks,
~sIf the code enters the while loop then tere are values within objDR so why not add a watch to this and check the value of objDr(0) and then objDR(1)

Hope that helps

Cheers
Gregor Suttie
I would say it is happening because there is no field in the result called "Cust ID", though there is one called "CustID"
Yes i know thats a silly mistake on my part. very silly... i wish i could delete this post. :) thanks very much. now i am doing it like objDR(0)

Regards.

System.IndexOutOfRangeException: There is no row at position 0

I'm getting a frustrating error that I can't seem to figure out with an update button. However, when I try to execute the Submit_Click sub I get the error that is the subject of this post. Can you see anything wrong with my code? The GetRecord sub work great on page_load to get the record in the first place, but in re-calling it it's not working.

Please help if you can, thanks!

Oh, E_ID refers to a context item (Dim E_ID as String = Context.Items("EmailID"))


Sub Submit_Click(Sender As Object, E As EventArgs)
GetRecord(E_ID)
Row = IndividualDS.Tables("Individual").Rows(0)
Row.Item("F_name") = FirstNameText.Text

Adapter.Update(IndividualDS, "Individual")
End Sub

Sub GetRecord(E_ID As String)
SelectStatement = "Select * From Individual Where Email='" & _
E_ID & "'"
ConnectString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & server.mappath("policy_dir.mdb")

Connect.ConnectionString = ConnectString
Adapter.SelectCommand = _
New OleDbCommand(SelectStatement, Connect)
Adapter.SelectCommand.Connection.Open
IndividualCB = New OleDBCommandBuilder(Adapter)
Adapter.Fill(IndividualDS, "Individual")
Adapter.SelectCommand.Connection.Close
End Sub

You may find some helphere.
Thank you, that did help.

I am closer... I am now getting an error that says "operation must use an updateable query" what should I check for to correct this?
Check the search result in Google.
Thanks, I think i got it fixed

System.IndexOutOfRangeException: Index was outside the bounds of the array

Hi i am getting the following error "System.IndexOutOfRangeException: Index was outside the bounds of the array". it is coming from this line of code ;

Line 595: // Build Column Name PartLine 596: strPart1 = strPart1 + "`" + strData[lngIter, 0] + "`,";Line 597:
It may have been caused by the following code;
staticpublicstring buildQuery(string strAction,string strTableName,string[,] strData,string[,] strWhere,string strWhereOverride,string strLimit,string strOffset,string strOrderBy)

{

// Array Definitions

//strData(x,0)=ColumnName

//strData(x,1)=ColumnData

 


You will get this if you use an index that is higher than the number of items in the array. So check if the lngIter is within the index range of the array so you don't pass an index which is higher than the total amount of items in the array.


Hi, i am quite new to programming, so i am unsure if i have declared the arrays properly, however i will show you some code and if you could tell me if you can identify where i have to declare the array.;

The following code is in the page calling up a method;

clsOBJ objDHOC =newclsOBJ();

Pmillio.clsOBJ.buildQuery("INSERT","tblProperty", strData, strWhere,"","1","1","strData");

string[,] strData =newstring[11, 2];

string[,] strWhere =newstring[11, 3];

strData[0, 0] ="StatutoryDate";

strData[0, 1] = txtDate.Text;

The following code is what in the DAL which the one above is referencing;

staticpublicstring buildQuery(string strAction,string strTableName,string[,] strData,string[,] strWhere,string strWhereOverride,string strLimit,string strOffset,string strOrderBy)

{

// Array Definitions

//strData(x,0)=ColumnName

//strData(x,1)=ColumnData

// Ucase

strAction = (strAction);

// Dimension

string strSQL;

int lngIter;

string strPart1 =null;

string strPart2 =null;