Showing posts with label sub. Show all posts
Showing posts with label sub. 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: 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

Saturday, March 24, 2012

system.net.socket question

I have the following code

Public Sub StartListening()
' Data buffer for incoming data.
Dim bytes() As Byte = New [Byte](128000) {}

' Establish the local endpoint for the socket.
Dim ipHostInfo As IPHostEntry = Dns.Resolve(Dns.GetHostName())
Dim ipAddress As IPAddress = ipHostInfo.AddressList(0)
Dim localEndPoint As New IPEndPoint(ipAddress, XXXXX)

' Intializes a TCP/IP socket.
Dim listener As New Socket(AddressFamily.InterNetwork, _
SocketType.Stream, ProtocolType.Tcp)

' Bind the socket to the local endpoint and listen for incoming
' connections.
Try
listener.Bind(localEndPoint)
listener.Listen(100)

While True
' Set the event to nonsignaled state.
allDone.Reset()

' Start an asynchronous socket to listen for connections.
listener.BeginAccept(New AsyncCallback(AddressOf AcceptCallback), _
listener)

' Wait until a connection is made before continuing.
allDone.WaitOne()
End While
Catch e As Exception
'Print out error message to log file
' Console.WriteLine(e.ToString()) '************
End Try
End Sub

Private Sub AcceptCallback(ByVal ar As IAsyncResult)
' Signal the main thread to continue.
allDone.Set()

' Get the socket that handles the client request.
Dim listener As Socket = CType(ar.AsyncState, Socket)
Dim handler As Socket = listener.EndAccept(ar)

' Create the state object.
Dim state As New StateObject
state.xSocket = handler
handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, _
New AsyncCallback(AddressOf readCallback), state)

End Sub

how do I get the IP address from the clients that connect to my sever?nevermind...i figured it out

Trey

System.NullReferenceException

I hope this is the right forum section. I am a getting started. Please take a look at this I can't seem to get this data connection to work.

Sub Page_Load()
Teamlist.Datasource = getteams
teamlist.databind()
End Sub

Function GetTeams() As System.Data.IDataReader
Dim connectionString As String = _
ConfigurationSettings.AppSettings("connectionstring")
Dim dbConnection = ConfigurationSettings.AppSettings("connectionstring")

Dim queryString As String = "SELECT [Teams].[TeamID], [Teams].[TeamName], [Teams].[Notes] FROM [Teams]"
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open
Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)

Return dataReader
End Function

Now I get this:
Exception Details: System.NullReferenceException: Object variable or With block variable not set.

Source Error:

Line 21: dbCommand.Connection = dbConnection
Line 22:
Line 23: dbConnection.Open
Line 24: Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Line 25:

Here is the contents of my web.config

<?xml version="1.0" encoding="UTF-8" ?
<configuration
<!--

The <appSettings> section is used to configure application-specific configuration
settings. These can be fetched from within apps by calling the
"ConfigurationSettings.AppSettings(key)" method:

<appSettings>
<add key="connectionstring"
value="Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4;
Data Source=C:\begaspnet11\wroxunited\database\wroxunited.mdb"/>
</appSettings
--
<system.web
<!--

The <sessionState" section is used to configure session state for the application.
It supports four modes: "Off", "InProc", "StateServer", and "SqlServer". The
later two modes enable session state to be stored off the web server machine -
allowing failure redundancy and web farm session state scenarios.

<sessionState mode="InProc"
stateConnectionString="tcpip=127.0.0.1:42424"
sqlConnectionString="data source=127.0.0.1;trusted_connection=true"
cookieless="false"
timeout="20" /
--
<!--

The <customErrors> section enables configuration of what to do if/when an
unhandled error occurs during the execution of a request. Specifically, it
enables developers to configure html error pages to be displayed in place of
a error stack trace:

<customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
<error statusCode="403" redirect="NoAccess.htm"/>
<error statusCode="404" redirect="FileNotFound.htm"/>
<customErrors
--
<!--

The <authentication> section enables configuration of the security authentication
mode used by ASP.NET to identify an incoming user. It supports a "mode"
attribute with four valid values: "Windows", "Forms", "Passport" and "None":

The <forms> section is a sub-section of the <authentication> section,
and supports configuring the authentication values used when Forms
authentication is enabled above:

<authentication mode="Windows"
<forms name=".ASPXAUTH"
loginUrl="login.aspx"
protection="Validation"
timeout="999999" /
</authentication
--
<!--

The <authorization> section enables developers/administrators to configure
whether a user or role has access to a particular page or resource. This is
accomplished by adding "<allow>" and "<deny>" sub-tags beneath the <authorization>
section - specifically detailing the users/roles allowed or denied access.

Note: The "?" character indicates "anonymous" users (ie: non authenticated users).
The "*" character indicates "all" users.

<authorization>
<allow users="joeuser" />
<allow roles="Admins" />
<deny users="*" />
</authorization
--
</system.web
</configuration>Hi,
Which line throw an error?
One problem I can see in your code is connection scope. DataReader can not be used if associated connection is closed. In your case connection (attached to command object) exists in scope of GetTeams scope and you are using DataReader out of this scope. It is wrong.
Line 23
dbconnection.open
Change this:


Dim dbConnection = ConfigurationSettings.AppSettings("connectionstring")

to:

Dim dbConnection as New SqlConnection()
dbConnection.ConnectionString = ConfigurationSettings.AppSettings("connectionstring")

dbConnection should be declared in the same scope where you are using associated datareader (see my previous reply)
1. Appreciate you working with me.

2. I'm using a Access mdb for this. How do that change this:

Dim dbConnection as New SqlConnection()

dbConnection.ConnectionString = ConfigurationSettings.AppSettings("connectionstring")

Thanks!
Rich
Sorry, I did not realize it is OleDb. Use this instead:


Dim dbConnection as New OleDbConnection()
dbConnection.ConnectionString = ConfigurationSettings.AppSettings("connectionstring")

Thanks but I got the same error.

The ConnectionString property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: The ConnectionString property has not been initialized.

Source Error:

Line 25: dbCommand.Connection = dbConnection
Line 26:
Line 27: dbConnection.Open
Line 28: Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Line 29:

Source File: C:\begasnet11\wroxunited\teams.aspx Line: 27

Stack Trace:

[InvalidOperationException: The ConnectionString property has not been initialized.]
System.Data.OleDb.OleDbConnection.Open() +203
ASP.teams_aspx.GetTeams() in C:\begasnet11\wroxunited\teams.aspx:27
ASP.teams_aspx.Page_Load() in C:\begasnet11\wroxunited\teams.aspx:9
System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +10
System.Web.UI.Control.OnLoad(EventArgs e) +55
System.Web.UI.Control.LoadRecursive() +27
System.Web.UI.Page.ProcessRequestMain() +731

------------------------

Dim dbConnection as New OleDbConnection(ConfigurationSettings.AppSettings("connectionstring"))
Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand("SELECT [Teams].[TeamID], [Teams].[TeamName], [Teams].[Notes] FROM [Teams]", dbConnection)
Constructors are faster than instantiating and then initializing (admittedly you won't be noticing the speed gain, but still, it's good to have performance in mind at all times).
Still nothing. I've tried this on 2 diffrent computers. Grasping at straws.

Same error.

Thanks!
Rich
Was this statement (dbConnection.ConnectionString = ConfigurationSettings.AppSettings("connectionstring") ) executed?
If it was, check dbConnection.ConnectionString value in debugger. May be Config file entry was not read correctly.
I set debug to true and this is what I got in addition to the same error

[InvalidOperationException: The ConnectionString property has not been initialized.]
System.Data.OleDb.OleDbConnection.Open() +203
ASP.teams_aspx.GetTeams() in C:\begasnet11\wroxunited\teams.aspx:26
ASP.teams_aspx.Page_Load() in C:\begasnet11\wroxunited\teams.aspx:10
System.Web.Util.ArglessEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +10
System.Web.UI.Control.OnLoad(EventArgs e) +55
System.Web.UI.Control.LoadRecursive() +27
System.Web.UI.Page.ProcessRequestMain() +731
Man I feel so dumb. OK here it is. The <appsettings> in the webconfig file was commented out. I removed the comment tags and bang.

Thanks everyone!!
Does it matter if this is in a folder or a virtual directory? Does the web config file need a virtual directory to work in like a global asa?

Thursday, March 22, 2012

System.NullReferenceException: Object reference not set to an instance of an object.

Why do I get above error message while executing this code:

Public Sub DropDown_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Dim list As DropDownList = CType(sender, DropDownList)
Dim cell = CType(list.Parent, TableCell)
Dim item = CType(cell.Parent, DataGridItem)
Dim index = item.ItemIndex

Dim ds As DataSet
ds = DataGrid1.DataSource

Dim row As DataRow
row = ds.Tables(0).Select("ID = '" + item.Cells(0).Text + "'")(0)
'<-- ERROR
End SubSet a break point on the line

row = ds.Tables(0).Select("ID = '" + item.Cells(0).Text + "'")(0)

and see what is null there.

Could be:
no tables in ds;
no Cells(o) in item;
no item;
select doesn't return anything
...

Debug it.

Eliyahu

"John Smith" <john.smith@.microsoft.com> wrote in message
news:%Zahg.3487$oj5.1152205@.news.siol.net...
> Why do I get above error message while executing this code:
> Public Sub DropDown_SelectedIndexChanged(ByVal sender As System.Object,
> ByVal e As System.EventArgs)
> Dim list As DropDownList = CType(sender, DropDownList)
> Dim cell = CType(list.Parent, TableCell)
> Dim item = CType(cell.Parent, DataGridItem)
> Dim index = item.ItemIndex
> Dim ds As DataSet
> ds = DataGrid1.DataSource
> Dim row As DataRow
> row = ds.Tables(0).Select("ID = '" + item.Cells(0).Text + "'")(0)
> '<-- ERROR
> End Sub
Thank you.

"ds" was null. It seems I need to add DataSource into Session object
somehow. Beginner mistake. It seems DataGrid1.DataSource is not persistance?
> "ds" was null. It seems I need to add DataSource into Session object
> somehow. Beginner mistake. It seems DataGrid1.DataSource is not
> persistance?

I've declared ds as global Shared variable and it works fine so far.
Just note, that global Shared variables are shared between user sessions. It
means that if there will be multiple users using the app in the same time,
they will affect each other.

Eliyahu

"John Smith" <john.smith@.microsoft.com> wrote in message
news:tWbhg.3493$oj5.1152346@.news.siol.net...
>> "ds" was null. It seems I need to add DataSource into Session object
>> somehow. Beginner mistake. It seems DataGrid1.DataSource is not
>> persistance?
> I've declared ds as global Shared variable and it works fine so far.
> Just note, that global Shared variables are shared between user sessions.
> It
> means that if there will be multiple users using the app in the same time,
> they will affect each other.

So, should I declare it as "static" or as simple global variable (without
"shared")?
What is your data source?

"John Smith" <john.smith@.microsoft.com> wrote in message
news:Dpchg.3498$oj5.1152406@.news.siol.net...
>> Just note, that global Shared variables are shared between user sessions.
>> It
>> means that if there will be multiple users using the app in the same
>> time, they will affect each other.
> So, should I declare it as "static" or as simple global variable (without
> "shared")?
> What is your data source?

XML
If you can't re-populate the datasource on every postback, you can store it
in a session variable.

Eliyahu

"John Smith" <john.smith@.microsoft.com> wrote in message
news:G7ehg.3500$oj5.1153527@.news.siol.net...
>> What is your data source?
> XML
> If you can't re-populate the datasource on every postback, you can store
> it
> in a session variable.

There is no other way but session object?
John Smith wrote:
>> If you can't re-populate the datasource on every postback, you can
>> store it
>> in a session variable.
> There is no other way but session object?
If you need it to be session-specific, the session object makes it easy.
Sure, you can create a global hashtable keyed by some property of the
users of your application, but
1. this hashtable could get rather large, and
2. if you are not careful, bugs are hard to avoid.

Just out of curiosity, what is your objection to the session object?
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
> Just out of curiosity, what is your objection to the session object?

I am beginner and I have never used it before. I'll try it now.
John Smith wrote:
>> Just out of curiosity, what is your objection to the session object?
> I am beginner and I have never used it before. I'll try it now.
Ah!
I typically use a pattern like this in my pages:

Private _CachedDS as dataset
Private Propery CachedDS() as dataset
Get
If _CachedDS Is Nothing Then
If Not Session("CachedDS") Is Nothing Then
_CachedDS = CType(Session("CachedDS"), dataset)
End If
End If
Return _CachedDS
End Get
Set(ByVal Value As dataset)
Session("CachedDS") = Value
_CachedDS = Value
End Set
End Property

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
BindDataGrid()
End If

End Sub

...
Sub BindDataGrid
Dim ds as dataset
if CachedDS Is Nothing then
FillDataSet()
End If
'bind the grid
Dim ds as dataset=CachedDS
With DataGrid1
.DataSource=ds
.DataMember = ...
.DataBind
End With

End Sub

Sub FillDataSet()
Try
CachedDS = DataLayer.RetrieveData(parms)
Catch ex
'handle error
End Try
End Sub

Public Sub DropDown_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Dim list As DropDownList = CType(sender, DropDownList)
Dim cell = CType(list.Parent, TableCell)
Dim item = CType(cell.Parent, DataGridItem)
Dim index = item.ItemIndex

Dim ds As DataSet
if not CachedDS is Nothing then
ds = CachedDS
Else
'throw an error? call FillDataset? up to you.
End If

Dim row As DataRow
row = ds.Tables(0).Select("ID = '" + item.Cells(0).Text +
"'")(0)
etc.

HTH,
Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
John Smith wrote:
>> Just note, that global Shared variables are shared between user
>> sessions. It
>> means that if there will be multiple users using the app in the same
>> time, they will affect each other.
> So, should I declare it as "static" or as simple global variable
> (without "shared")?

You should probably store it in Session rather than declaring it "Global
Shared"

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

System.NullReferenceException: Object reference not set to an instance of an object.

Why do I get above error message while executing this code:
Public Sub DropDown_SelectedIndexChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Dim list As DropDownList = CType(sender, DropDownList)
Dim cell = CType(list.Parent, TableCell)
Dim item = CType(cell.Parent, DataGridItem)
Dim index = item.ItemIndex
Dim ds As DataSet
ds = DataGrid1.DataSource
Dim row As DataRow
row = ds.Tables(0).Select("ID = '" + item.Cells(0).Text + "'")(0)
'<-- ERROR
End SubSet a break point on the line
row = ds.Tables(0).Select("ID = '" + item.Cells(0).Text + "'")(0)
and see what is null there.
Could be:
no tables in ds;
no Cells(o) in item;
no item;
select doesn't return anything
...
Debug it.
Eliyahu
"John Smith" <john.smith@.microsoft.com> wrote in message
news:%Zahg.3487$oj5.1152205@.news.siol.net...
> Why do I get above error message while executing this code:
> Public Sub DropDown_SelectedIndexChanged(ByVal sender As System.Object,
> ByVal e As System.EventArgs)
> Dim list As DropDownList = CType(sender, DropDownList)
> Dim cell = CType(list.Parent, TableCell)
> Dim item = CType(cell.Parent, DataGridItem)
> Dim index = item.ItemIndex
> Dim ds As DataSet
> ds = DataGrid1.DataSource
> Dim row As DataRow
> row = ds.Tables(0).Select("ID = '" + item.Cells(0).Text + "'")(0)
> '<-- ERROR
> End Sub
>
Thank you.
"ds" was null. It seems I need to add DataSource into Session object
somehow. Beginner mistake. It seems DataGrid1.DataSource is not persistance?

> "ds" was null. It seems I need to add DataSource into Session object
> somehow. Beginner mistake. It seems DataGrid1.DataSource is not
> persistance?
I've declared ds as global Shared variable and it works fine so far.
Just note, that global Shared variables are shared between user sessions. It
means that if there will be multiple users using the app in the same time,
they will affect each other.
Eliyahu
"John Smith" <john.smith@.microsoft.com> wrote in message
news:tWbhg.3493$oj5.1152346@.news.siol.net...
>
> I've declared ds as global Shared variable and it works fine so far.
>

> Just note, that global Shared variables are shared between user sessions.
> It
> means that if there will be multiple users using the app in the same time,
> they will affect each other.
So, should I declare it as "static" or as simple global variable (without
"shared")?
What is your data source?
"John Smith" <john.smith@.microsoft.com> wrote in message
news:Dpchg.3498$oj5.1152406@.news.siol.net...
>
> So, should I declare it as "static" or as simple global variable (without
> "shared")?
>

> What is your data source?
XML
If you can't re-populate the datasource on every postback, you can store it
in a session variable.
Eliyahu
"John Smith" <john.smith@.microsoft.com> wrote in message
news:G7ehg.3500$oj5.1153527@.news.siol.net...
>
> XML
>

> If you can't re-populate the datasource on every postback, you can store
> it
> in a session variable.
There is no other way but session object?