Hi, I'm obtaining this error and I don't not why: System.IndexOutOfRangeException: No se puede encontrar la tabla
0. / System.IndexOutOfRangeException:It's not possibble to find table 0
I obtain the error on this line: For Each dr As DataRow In dsNoMoved.Tables(0).Rows
Of this function: Protected Sub Calendar1_DayRender
I've checked the vars and all of them has a value
The query works on ok on my DB.
I'm doing a calendar and I take with this too much time. I hope you could help me.
Protected dsNoMoved As DataSet
Protected Sub activarcalendario(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnusuariocalendario.Click
MyCalendar.VisibleDate = Date.Today
FillHolidayDataset()
End Sub
Protected Sub FillHolidayDataset()
Dim firstDate As New DateTime(MyCalendar.VisibleDate.Year, MyCalendar.VisibleDate.Month, 1)
Dim today As DateTime = Date.Today
dsNoMoved = GetCurrentMonthNoMoved(firstDate, today)
End Sub
Protected Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles MyCalendar.VisibleMonthChanged
FillHolidayDataset()
End Sub
Function GetCurrentMonthNoMoved(ByVal firstDate As DateTime, ByVal today As DateTime) As DataSet
Dim dsNoMovido As New DataSet
Dim usuario As String = Me.tbusuariocalendario.Text
Me.Label5.Text = usuario
Me.Label6.Text = firstDate
Me.Label8.Text = today
Try
Dim cs As ConnectionStringSettings
cs = ConfigurationManager.ConnectionStrings("MiConexion")
Dim connString As String = cs.ConnectionString
Dim dbConnection As New SqlConnection(connString)
Dim querynomovido As String = "SELECT no_movido.fecha FROM no_movido, (SELECT id_vehiculo AS id_veh FROM vehiculo_adapt WHERE vehiculo_adapt.usuario = @usuario) WHERE no_movido.fecha >= @firstDate AND no_movido.fecha < @today AND no_movido.id_vehiculo = id_veh"
Dim dbCommand As New SqlCommand(querynomovido, dbConnection)
dbCommand.Parameters.Add(New SqlParameter("@usuario", usuario))
dbCommand.Parameters.Add(New SqlParameter("@firstDate", firstDate))
dbCommand.Parameters.Add(New SqlParameter("@today", today))
Dim sqlDataAdapter As New SqlDataAdapter(dbCommand)
sqlDataAdapter.Fill(dsNoMovido)
Catch ex As Exception
Me.lblerrorcalendario.Text = ex.ToString
End Try
Return dsNoMovido
End Function
Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles MyCalendar.DayRender
Dim nextDate As DateTime
If Not dsNoMoved Is Nothing Then
For Each dr As DataRow In dsNoMoved.Tables(0).Rows
nextDate = CType(dr("fecha"), DateTime)
If nextDate = e.Day.Date Then
e.Cell.BackColor = System.Drawing.Color.CornflowerBlue
e.Day.IsSelectable = True
End If
Next
End If
End Sub
End Class
Ever than a programmer makes an extra hour god kills a kitten
If (dsNoMoved.Tables.Count > 0) Then
For Each dr As DataRow In dsNoMoved.Tables(0).Rows
nextDate = CType(dr("fecha"), DateTime)
If nextDate = e.Day.Date Then
e.Cell.BackColor = System.Drawing.Color.CornflowerBlue
e.Day.IsSelectable = True
End If
Next
End If
I obtain this error: Object reference notset to an instanceof an object.
Ever than a programmer makes an extra hour god kills a kitten
kilofafeure
Participant
1507 Points
752 Posts
Error on dataset
Aug 04, 2011 12:10 PM|LINK
Hi, I'm obtaining this error and I don't not why: System.IndexOutOfRangeException: No se puede encontrar la tabla 0. / System.IndexOutOfRangeException:It's not possibble to find table 0
I obtain the error on this line: For Each dr As DataRow In dsNoMoved.Tables(0).Rows
Of this function: Protected Sub Calendar1_DayRender
I've checked the vars and all of them has a value
The query works on ok on my DB.
I'm doing a calendar and I take with this too much time. I hope you could help me.
Protected dsNoMoved As DataSet Protected Sub activarcalendario(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnusuariocalendario.Click MyCalendar.VisibleDate = Date.Today FillHolidayDataset() End Sub Protected Sub FillHolidayDataset() Dim firstDate As New DateTime(MyCalendar.VisibleDate.Year, MyCalendar.VisibleDate.Month, 1) Dim today As DateTime = Date.Today dsNoMoved = GetCurrentMonthNoMoved(firstDate, today) End Sub Protected Sub Calendar1_VisibleMonthChanged(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MonthChangedEventArgs) Handles MyCalendar.VisibleMonthChanged FillHolidayDataset() End Sub Function GetCurrentMonthNoMoved(ByVal firstDate As DateTime, ByVal today As DateTime) As DataSet Dim dsNoMovido As New DataSet Dim usuario As String = Me.tbusuariocalendario.Text Me.Label5.Text = usuario Me.Label6.Text = firstDate Me.Label8.Text = today Try Dim cs As ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings("MiConexion") Dim connString As String = cs.ConnectionString Dim dbConnection As New SqlConnection(connString) Dim querynomovido As String = "SELECT no_movido.fecha FROM no_movido, (SELECT id_vehiculo AS id_veh FROM vehiculo_adapt WHERE vehiculo_adapt.usuario = @usuario) WHERE no_movido.fecha >= @firstDate AND no_movido.fecha < @today AND no_movido.id_vehiculo = id_veh" Dim dbCommand As New SqlCommand(querynomovido, dbConnection) dbCommand.Parameters.Add(New SqlParameter("@usuario", usuario)) dbCommand.Parameters.Add(New SqlParameter("@firstDate", firstDate)) dbCommand.Parameters.Add(New SqlParameter("@today", today)) Dim sqlDataAdapter As New SqlDataAdapter(dbCommand) sqlDataAdapter.Fill(dsNoMovido) Catch ex As Exception Me.lblerrorcalendario.Text = ex.ToString End Try Return dsNoMovido End Function Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles MyCalendar.DayRender Dim nextDate As DateTime If Not dsNoMoved Is Nothing Then For Each dr As DataRow In dsNoMoved.Tables(0).Rows nextDate = CType(dr("fecha"), DateTime) If nextDate = e.Day.Date Then e.Cell.BackColor = System.Drawing.Color.CornflowerBlue e.Day.IsSelectable = True End If Next End If End Sub End Classrkbvasanths@...
Participant
957 Points
236 Posts
Re: Error on dataset
Aug 04, 2011 12:13 PM|LINK
Your dataset doesnt contain any datatable. thats why u r geting this error
before accessing dsNoMoved.Tables(0).Row,s please do a validation like
if (dsNoMoved.Tables.Count>0)
{
......
}
Thanks,
Vasanth R, MCTS(SQL 2005 & SQL 2008 BI), MCP
http://dotnetcodeguide.blogspot.com
shree_ars
Participant
1395 Points
776 Posts
Re: Error on dataset
Aug 04, 2011 12:14 PM|LINK
try to load your query seperately, whether its get executable for specified conditions.
Move over may i know at which point you getting the exception?
kilofafeure
Participant
1507 Points
752 Posts
Re: Error on dataset
Aug 04, 2011 12:16 PM|LINK
But the query works ok on my db, and I've put the same data.
shree_ars
Participant
1395 Points
776 Posts
Re: Error on dataset
Aug 04, 2011 12:18 PM|LINK
which event calling first, prerender or load?
If its prerender then you have to validate the table count in dataset. as per rkb.... said
kilofafeure
Participant
1507 Points
752 Posts
Re: Error on dataset
Aug 04, 2011 12:20 PM|LINK
I don't understand you with with prerender or load. What do you mean?
kilofafeure
Participant
1507 Points
752 Posts
Re: Error on dataset
Aug 04, 2011 12:21 PM|LINK
Why d'ont works this validation?
shree_ars
Participant
1395 Points
776 Posts
Re: Error on dataset
Aug 04, 2011 12:25 PM|LINK
nothing will get work on once u assign new dataset object.
before the query executeing the prerender event get fired so the exception came...
event if not records or table loaded in dataset after the query excuetion, nothing wont work, u need to check only the table count.
Nothing is simply the unassigned object.
kilofafeure
Participant
1507 Points
752 Posts
Re: Error on dataset
Aug 04, 2011 12:26 PM|LINK
Doing it as you says:
If (dsNoMoved.Tables.Count > 0) Then For Each dr As DataRow In dsNoMoved.Tables(0).Rows nextDate = CType(dr("fecha"), DateTime) If nextDate = e.Day.Date Then e.Cell.BackColor = System.Drawing.Color.CornflowerBlue e.Day.IsSelectable = True End If Next End IfI obtain this error: Object reference not set to an instance of an object.
shree_ars
Participant
1395 Points
776 Posts
Re: Error on dataset
Aug 04, 2011 12:29 PM|LINK
ok. may i know the sequence of event get called in your code, calendar_prerender, database access.. etc