473,809 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Disconnected Datatsets?

J
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

ip()

If Not IsPostBack Then

DataGrid1.DataB ind()

End If

End Sub

Sub ip()

Dim newrow As DataRow

SqlConnection1. Open()

SqlCommand1.Par ameters("@membe rs").Value = "1007,4200, 999"

daTest.SelectCo mmand = SqlCommand1

daTest.Fill(dsT est, "TestTable" )

Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
DataViewRowStat e.CurrentRows)

DataGrid1.DataS ource = dvTest

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "1"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim newrow As DataRow

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "2"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

DataGrid1.DataB ind()

End Sub

When I click the button, I would have thought that the datagrid would keep
increasing with the values "2,", "Jason", "1", but it doesn't.

I believe I have what is called a disconnected dataset, and I need the user
to work on a dataset before they post the final values to the server, hence
why I'm not using a SQL Adapter.

Can someone PLEASE explain why the above won't work, and how to work with
disconnected datasets.

TIA

Nov 17 '05 #1
5 1049
J,

Every time you load your page the dataset is being recreated. You need to
either first save the new row to the database or only get the dataset the
first page load and then store it in memory (a session variable or the like)
between page views.

Since the web is a stateless environment (all objects are destroyed after
rendering a page) you have to take measures to store the objects you need to
remain between posts.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J" <nospam> wrote in message news:eg******** ******@tk2msftn gp13.phx.gbl...
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

ip()

If Not IsPostBack Then

DataGrid1.DataB ind()

End If

End Sub

Sub ip()

Dim newrow As DataRow

SqlConnection1. Open()

SqlCommand1.Par ameters("@membe rs").Value = "1007,4200, 999"

daTest.SelectCo mmand = SqlCommand1

daTest.Fill(dsT est, "TestTable" )

Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
DataViewRowStat e.CurrentRows)

DataGrid1.DataS ource = dvTest

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "1"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim newrow As DataRow

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "2"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

DataGrid1.DataB ind()

End Sub

When I click the button, I would have thought that the datagrid would keep
increasing with the values "2,", "Jason", "1", but it doesn't.

I believe I have what is called a disconnected dataset, and I need the user to work on a dataset before they post the final values to the server, hence why I'm not using a SQL Adapter.

Can someone PLEASE explain why the above won't work, and how to work with
disconnected datasets.

TIA


Nov 17 '05 #2
J
A session variable!!

How would I store the dataset as a session variable?

Would it be simply session("Temp") =dsTest.tables( "TestTable" )

TIA

"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:uU******** ******@tk2msftn gp13.phx.gbl...
J,

Every time you load your page the dataset is being recreated. You need to
either first save the new row to the database or only get the dataset the
first page load and then store it in memory (a session variable or the like) between page views.

Since the web is a stateless environment (all objects are destroyed after
rendering a page) you have to take measures to store the objects you need to remain between posts.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J" <nospam> wrote in message

news:eg******** ******@tk2msftn gp13.phx.gbl...
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

ip()

If Not IsPostBack Then

DataGrid1.DataB ind()

End If

End Sub

Sub ip()

Dim newrow As DataRow

SqlConnection1. Open()

SqlCommand1.Par ameters("@membe rs").Value = "1007,4200, 999"

daTest.SelectCo mmand = SqlCommand1

daTest.Fill(dsT est, "TestTable" )

Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
DataViewRowStat e.CurrentRows)

DataGrid1.DataS ource = dvTest

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "1"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim newrow As DataRow

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "2"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

DataGrid1.DataB ind()

End Sub

When I click the button, I would have thought that the datagrid would keep increasing with the values "2,", "Jason", "1", but it doesn't.

I believe I have what is called a disconnected dataset, and I need the

user
to work on a dataset before they post the final values to the server,

hence
why I'm not using a SQL Adapter.

Can someone PLEASE explain why the above won't work, and how to work with disconnected datasets.

TIA



Nov 17 '05 #3
J,

You have to both store the datatable in the session variable and get it out
again when you go to use it.

Change your code to this: (I've put '********* above the new lines of code.)

'Put user code to initialize the page here

ip() '*******Move this (It should only fire the first page load)

dsTest = Session("Temp") '***********Mov e this (It should only be done on
post back)

If Not IsPostBack Then

ip() '*******Moved here.

DataGrid1.DataB ind()

Else

dsTest = Session("Temp")

End If

End Sub

Sub ip()

Dim newrow As DataRow

SqlConnection1. Open()

SqlCommand1.Par ameters("@membe rs").Value = "1007,4200, 999"

daTest.SelectCo mmand = SqlCommand1

daTest.Fill(dsT est, "TestTable" )

Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
DataViewRowStat e.CurrentRows)

DataGrid1.DataS ource = dvTest

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "1"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

Session("Temp") = dsTest '*********Add the datatable to the session

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim newrow As DataRow

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "2"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

Session("Temp") = dsTest.Tables(" TestTable")

DataGrid1.DataB ind()

End Sub

Sincerely,
--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J" <nospam> wrote in message news:ew******** ******@TK2MSFTN GP10.phx.gbl...
Well My code now looks like...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

ip()

dsTest = Session("Temp")

If Not IsPostBack Then

DataGrid1.DataB ind()

End If

End Sub

Sub ip()

Dim newrow As DataRow

SqlConnection1. Open()

SqlCommand1.Par ameters("@membe rs").Value = "1007,4200, 999"

daTest.SelectCo mmand = SqlCommand1

daTest.Fill(dsT est, "TestTable" )

Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
DataViewRowStat e.CurrentRows)

DataGrid1.DataS ource = dvTest

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "1"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim newrow As DataRow

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "2"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

Session("Temp") = dsTest.Tables(" TestTable")

DataGrid1.DataB ind()

End Sub

And I'm getting an error saying...

Object reference not set to an instance of an object.
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.NullRefe renceException: Object reference not set
to an instance of an object.

Source Error:

Line 74: Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button1.Click
Line 75: Dim newrow As DataRow
Line 76: newrow = dsTest.Tables(" TestTable").New Row
Line 77: newrow(0) = "2"
Line 78: newrow(1) = "Jason"


Source File: c:\inetpub\wwwr oot\hbitl_umc\t est.aspx.vb Line: 76

Am I really doing this right?

"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:#k******** ******@TK2MSFTN GP09.phx.gbl...
Well, your code is storing just the table itself not the whole dataset (I
think that's all you need for your purposes here, but yes, that's it!

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J" <nospam> wrote in message news:eO******** *****@tk2msftng p13.phx.gbl...
A session variable!!

How would I store the dataset as a session variable?

Would it be simply session("Temp") =dsTest.tables( "TestTable" )

TIA

"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:uU******** ******@tk2msftn gp13.phx.gbl...
> J,
>
> Every time you load your page the dataset is being recreated. You need to
> either first save the new row to the database or only get the
dataset
the
> first page load and then store it in memory (a session variable or

the like)
> between page views.
>
> Since the web is a stateless environment (all objects are destroyed

after
> rendering a page) you have to take measures to store the objects you

need
to
> remain between posts.
>
> Sincerely,
>
> --
> S. Justin Gengo, MCP
> Web Developer
>
> Free code library at:
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzche
>
>
> "J" <nospam> wrote in message
news:eg******** ******@tk2msftn gp13.phx.gbl...
> > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> > System.EventArg s) Handles MyBase.Load
> >
> > 'Put user code to initialize the page here
> >
> > ip()
> >
> > If Not IsPostBack Then
> >
> > DataGrid1.DataB ind()
> >
> > End If
> >
> > End Sub
> >
> > Sub ip()
> >
> > Dim newrow As DataRow
> >
> >
> >
> >
> >
> > SqlConnection1. Open()
> >
> > SqlCommand1.Par ameters("@membe rs").Value = "1007,4200, 999"
> >
> > daTest.SelectCo mmand = SqlCommand1
> >
> > daTest.Fill(dsT est, "TestTable" )
> >
> > Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
> > DataViewRowStat e.CurrentRows)
> >
> > DataGrid1.DataS ource = dvTest
> >
> > newrow = dsTest.Tables(" TestTable").New Row
> >
> > newrow(0) = "1"
> >
> > newrow(1) = "Jason"
> >
> > newrow(2) = "1"
> >
> > dsTest.Tables(" TestTable").Row s.Add(newrow)
> >
> > dsTest.AcceptCh anges()
> >
> > End Sub
> >
> > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As > > System.EventArg s) Handles Button1.Click
> >
> > Dim newrow As DataRow
> >
> > newrow = dsTest.Tables(" TestTable").New Row
> >
> > newrow(0) = "2"
> >
> > newrow(1) = "Jason"
> >
> > newrow(2) = "1"
> >
> > dsTest.Tables(" TestTable").Row s.Add(newrow)
> >
> > dsTest.AcceptCh anges()
> >
> > DataGrid1.DataB ind()
> >
> > End Sub
> >
> >
> >
> > When I click the button, I would have thought that the datagrid

would keep
> > increasing with the values "2,", "Jason", "1", but it doesn't.
> >
> > I believe I have what is called a disconnected dataset, and I need the > user
> > to work on a dataset before they post the final values to the server, > hence
> > why I'm not using a SQL Adapter.
> >
> > Can someone PLEASE explain why the above won't work, and how to work with
> > disconnected datasets.
> >
> > TIA
> >
> >
> >
> >
> >
>
>



Nov 17 '05 #4
J
Well, I've changed the code accordingly, it now looks like...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

If Not IsPostBack Then

ip()

DataGrid1.DataB ind()

Else

dsTest = Session("Temp")

End If

End Sub

Sub ip()

Dim newrow As DataRow

SqlConnection1. Open()

SqlCommand1.Par ameters("@membe rs").Value = "1007,4200,9999 "

daTest.SelectCo mmand = SqlCommand1

daTest.Fill(dsT est, "TestTable" )

Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
DataViewRowStat e.CurrentRows)

DataGrid1.DataS ource = dvTest

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "1"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

Session("Temp") = dsTest

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim newrow As DataRow

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "2"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

Session("Temp") = dsTest.Tables(" TestTable")

DataGrid1.DataB ind()

End Sub

When I run, and click the button, the datagrid disappears.

When I click it a second time, I'm told ...

Specified cast is not valid.
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.InvalidC astException: Specified cast is not valid.

Source Error:

Line 49: DataGrid1.DataB ind()
Line 50: Else
Line 51: dsTest = Session("Temp")
Line 52: End If
Line 53:


Source File: c:\inetpub\wwwr oot\hbitl_umc\t est.aspx.vb Line: 51





"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:#E******** ******@TK2MSFTN GP10.phx.gbl...
J,

You have to both store the datatable in the session variable and get it out again when you go to use it.

Change your code to this: (I've put '********* above the new lines of code.)
'Put user code to initialize the page here

ip() '*******Move this (It should only fire the first page load)

dsTest = Session("Temp") '***********Mov e this (It should only be done on
post back)

If Not IsPostBack Then

ip() '*******Moved here.

DataGrid1.DataB ind()

Else

dsTest = Session("Temp")

End If

End Sub

Sub ip()

Dim newrow As DataRow

SqlConnection1. Open()

SqlCommand1.Par ameters("@membe rs").Value = "1007,4200, 999"

daTest.SelectCo mmand = SqlCommand1

daTest.Fill(dsT est, "TestTable" )

Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
DataViewRowStat e.CurrentRows)

DataGrid1.DataS ource = dvTest

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "1"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

Session("Temp") = dsTest '*********Add the datatable to the session

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim newrow As DataRow

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "2"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

Session("Temp") = dsTest.Tables(" TestTable")

DataGrid1.DataB ind()

End Sub

Sincerely,
--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J" <nospam> wrote in message

news:ew******** ******@TK2MSFTN GP10.phx.gbl...
Well My code now looks like...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

ip()

dsTest = Session("Temp")

If Not IsPostBack Then

DataGrid1.DataB ind()

End If

End Sub

Sub ip()

Dim newrow As DataRow

SqlConnection1. Open()

SqlCommand1.Par ameters("@membe rs").Value = "1007,4200, 999"

daTest.SelectCo mmand = SqlCommand1

daTest.Fill(dsT est, "TestTable" )

Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
DataViewRowStat e.CurrentRows)

DataGrid1.DataS ource = dvTest

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "1"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim newrow As DataRow

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "2"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

Session("Temp") = dsTest.Tables(" TestTable")

DataGrid1.DataB ind()

End Sub

And I'm getting an error saying...

Object reference not set to an instance of an object.
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.NullRefe renceException: Object reference not set
to an instance of an object.

Source Error:

Line 74: Private Sub Button1_Click(B yVal sender As System.Object,

ByVal
e As System.EventArg s) Handles Button1.Click
Line 75: Dim newrow As DataRow
Line 76: newrow = dsTest.Tables(" TestTable").New Row
Line 77: newrow(0) = "2"
Line 78: newrow(1) = "Jason"


Source File: c:\inetpub\wwwr oot\hbitl_umc\t est.aspx.vb Line: 76

Am I really doing this right?

"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:#k******** ******@TK2MSFTN GP09.phx.gbl...
Well, your code is storing just the table itself not the whole dataset (I think that's all you need for your purposes here, but yes, that's it!

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J" <nospam> wrote in message news:eO******** *****@tk2msftng p13.phx.gbl... > A session variable!!
>
> How would I store the dataset as a session variable?
>
> Would it be simply session("Temp") =dsTest.tables( "TestTable" )
>
> TIA
>
> "S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
> news:uU******** ******@tk2msftn gp13.phx.gbl...
> > J,
> >
> > Every time you load your page the dataset is being recreated. You need to
> > either first save the new row to the database or only get the dataset the
> > first page load and then store it in memory (a session variable or the > like)
> > between page views.
> >
> > Since the web is a stateless environment (all objects are destroyed after
> > rendering a page) you have to take measures to store the objects you need
> to
> > remain between posts.
> >
> > Sincerely,
> >
> > --
> > S. Justin Gengo, MCP
> > Web Developer
> >
> > Free code library at:
> > www.aboutfortunate.com
> >
> > "Out of chaos comes order."
> > Nietzche
> >
> >
> > "J" <nospam> wrote in message
> news:eg******** ******@tk2msftn gp13.phx.gbl...
> > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> > > System.EventArg s) Handles MyBase.Load
> > >
> > > 'Put user code to initialize the page here
> > >
> > > ip()
> > >
> > > If Not IsPostBack Then
> > >
> > > DataGrid1.DataB ind()
> > >
> > > End If
> > >
> > > End Sub
> > >
> > > Sub ip()
> > >
> > > Dim newrow As DataRow
> > >
> > >
> > >
> > >
> > >
> > > SqlConnection1. Open()
> > >
> > > SqlCommand1.Par ameters("@membe rs").Value = "1007,4200, 999"
> > >
> > > daTest.SelectCo mmand = SqlCommand1
> > >
> > > daTest.Fill(dsT est, "TestTable" )
> > >
> > > Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
> > > DataViewRowStat e.CurrentRows)
> > >
> > > DataGrid1.DataS ource = dvTest
> > >
> > > newrow = dsTest.Tables(" TestTable").New Row
> > >
> > > newrow(0) = "1"
> > >
> > > newrow(1) = "Jason"
> > >
> > > newrow(2) = "1"
> > >
> > > dsTest.Tables(" TestTable").Row s.Add(newrow)
> > >
> > > dsTest.AcceptCh anges()
> > >
> > > End Sub
> > >
> > > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As > > > System.EventArg s) Handles Button1.Click
> > >
> > > Dim newrow As DataRow
> > >
> > > newrow = dsTest.Tables(" TestTable").New Row
> > >
> > > newrow(0) = "2"
> > >
> > > newrow(1) = "Jason"
> > >
> > > newrow(2) = "1"
> > >
> > > dsTest.Tables(" TestTable").Row s.Add(newrow)
> > >
> > > dsTest.AcceptCh anges()
> > >
> > > DataGrid1.DataB ind()
> > >
> > > End Sub
> > >
> > >
> > >
> > > When I click the button, I would have thought that the datagrid

would
> keep
> > > increasing with the values "2,", "Jason", "1", but it doesn't.
> > >
> > > I believe I have what is called a disconnected dataset, and I
need the
> > user
> > > to work on a dataset before they post the final values to the

server,
> > hence
> > > why I'm not using a SQL Adapter.
> > >
> > > Can someone PLEASE explain why the above won't work, and how to

work > with
> > > disconnected datasets.
> > >
> > > TIA
> > >
> > >
> > >
> > >
> > >
> >
> >
>
>



Nov 17 '05 #5
J,

It's because the datasource of your table is actually the dataview. Inside
of the button click's event handler you need to recreate the dataview and
set it as the datasource of the grid before you rebind the grid.

Sincerely,

--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J" <nospam> wrote in message news:Oj******** ******@TK2MSFTN GP09.phx.gbl...
Well, I've changed the code accordingly, it now looks like...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

If Not IsPostBack Then

ip()

DataGrid1.DataB ind()

Else

dsTest = Session("Temp")

End If

End Sub

Sub ip()

Dim newrow As DataRow

SqlConnection1. Open()

SqlCommand1.Par ameters("@membe rs").Value = "1007,4200,9999 "

daTest.SelectCo mmand = SqlCommand1

daTest.Fill(dsT est, "TestTable" )

Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
DataViewRowStat e.CurrentRows)

DataGrid1.DataS ource = dvTest

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "1"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

Session("Temp") = dsTest

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim newrow As DataRow

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "2"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

Session("Temp") = dsTest.Tables(" TestTable")

DataGrid1.DataB ind()

End Sub

When I run, and click the button, the datagrid disappears.

When I click it a second time, I'm told ...

Specified cast is not valid.
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.InvalidC astException: Specified cast is not valid.
Source Error:

Line 49: DataGrid1.DataB ind()
Line 50: Else
Line 51: dsTest = Session("Temp")
Line 52: End If
Line 53:


Source File: c:\inetpub\wwwr oot\hbitl_umc\t est.aspx.vb Line: 51





"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:#E******** ******@TK2MSFTN GP10.phx.gbl...
J,

You have to both store the datatable in the session variable and get it

out
again when you go to use it.

Change your code to this: (I've put '********* above the new lines of

code.)

'Put user code to initialize the page here

ip() '*******Move this (It should only fire the first page load)

dsTest = Session("Temp") '***********Mov e this (It should only be done on
post back)

If Not IsPostBack Then

ip() '*******Moved here.

DataGrid1.DataB ind()

Else

dsTest = Session("Temp")

End If

End Sub

Sub ip()

Dim newrow As DataRow

SqlConnection1. Open()

SqlCommand1.Par ameters("@membe rs").Value = "1007,4200, 999"

daTest.SelectCo mmand = SqlCommand1

daTest.Fill(dsT est, "TestTable" )

Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
DataViewRowStat e.CurrentRows)

DataGrid1.DataS ource = dvTest

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "1"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

Session("Temp") = dsTest '*********Add the datatable to the session

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim newrow As DataRow

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "2"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

Session("Temp") = dsTest.Tables(" TestTable")

DataGrid1.DataB ind()

End Sub

Sincerely,
--
S. Justin Gengo, MCP
Web Developer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"J" <nospam> wrote in message

news:ew******** ******@TK2MSFTN GP10.phx.gbl... Well My code now looks like...

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load

'Put user code to initialize the page here

ip()

dsTest = Session("Temp")

If Not IsPostBack Then

DataGrid1.DataB ind()

End If

End Sub

Sub ip()

Dim newrow As DataRow

SqlConnection1. Open()

SqlCommand1.Par ameters("@membe rs").Value = "1007,4200, 999"

daTest.SelectCo mmand = SqlCommand1

daTest.Fill(dsT est, "TestTable" )

Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
DataViewRowStat e.CurrentRows)

DataGrid1.DataS ource = dvTest

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "1"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

End Sub

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim newrow As DataRow

newrow = dsTest.Tables(" TestTable").New Row

newrow(0) = "2"

newrow(1) = "Jason"

newrow(2) = "1"

dsTest.Tables(" TestTable").Row s.Add(newrow)

dsTest.AcceptCh anges()

Session("Temp") = dsTest.Tables(" TestTable")

DataGrid1.DataB ind()

End Sub

And I'm getting an error saying...

Object reference not set to an instance of an object.
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.NullRefe renceException: Object reference not set to an instance of an object.

Source Error:

Line 74: Private Sub Button1_Click(B yVal sender As System.Object,

ByVal
e As System.EventArg s) Handles Button1.Click
Line 75: Dim newrow As DataRow
Line 76: newrow = dsTest.Tables(" TestTable").New Row
Line 77: newrow(0) = "2"
Line 78: newrow(1) = "Jason"


Source File: c:\inetpub\wwwr oot\hbitl_umc\t est.aspx.vb Line: 76

Am I really doing this right?

"S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
news:#k******** ******@TK2MSFTN GP09.phx.gbl...
> Well, your code is storing just the table itself not the whole dataset
(I
> think that's all you need for your purposes here, but yes, that's
it! >
> Sincerely,
>
> --
> S. Justin Gengo, MCP
> Web Developer
>
> Free code library at:
> www.aboutfortunate.com
>
> "Out of chaos comes order."
> Nietzche
>
>
> "J" <nospam> wrote in message

news:eO******** *****@tk2msftng p13.phx.gbl...
> > A session variable!!
> >
> > How would I store the dataset as a session variable?
> >
> > Would it be simply session("Temp") =dsTest.tables( "TestTable" )
> >
> > TIA
> >
> > "S. Justin Gengo" <sj*****@aboutf ortunate.com> wrote in message
> > news:uU******** ******@tk2msftn gp13.phx.gbl...
> > > J,
> > >
> > > Every time you load your page the dataset is being recreated. You
need
> to
> > > either first save the new row to the database or only get the

dataset
> the
> > > first page load and then store it in memory (a session variable
or the
> > like)
> > > between page views.
> > >
> > > Since the web is a stateless environment (all objects are destroyed > after
> > > rendering a page) you have to take measures to store the objects you > need
> > to
> > > remain between posts.
> > >
> > > Sincerely,
> > >
> > > --
> > > S. Justin Gengo, MCP
> > > Web Developer
> > >
> > > Free code library at:
> > > www.aboutfortunate.com
> > >
> > > "Out of chaos comes order."
> > > Nietzche
> > >
> > >
> > > "J" <nospam> wrote in message
> > news:eg******** ******@tk2msftn gp13.phx.gbl...
> > > > Private Sub Page_Load(ByVal sender As System.Object, ByVal e
As > > > > System.EventArg s) Handles MyBase.Load
> > > >
> > > > 'Put user code to initialize the page here
> > > >
> > > > ip()
> > > >
> > > > If Not IsPostBack Then
> > > >
> > > > DataGrid1.DataB ind()
> > > >
> > > > End If
> > > >
> > > > End Sub
> > > >
> > > > Sub ip()
> > > >
> > > > Dim newrow As DataRow
> > > >
> > > >
> > > >
> > > >
> > > >
> > > > SqlConnection1. Open()
> > > >
> > > > SqlCommand1.Par ameters("@membe rs").Value = "1007,4200, 999"
> > > >
> > > > daTest.SelectCo mmand = SqlCommand1
> > > >
> > > > daTest.Fill(dsT est, "TestTable" )
> > > >
> > > > Dim dvTest As New DataView(dsTest .Tables("TestTa ble"), "", "",
> > > > DataViewRowStat e.CurrentRows)
> > > >
> > > > DataGrid1.DataS ource = dvTest
> > > >
> > > > newrow = dsTest.Tables(" TestTable").New Row
> > > >
> > > > newrow(0) = "1"
> > > >
> > > > newrow(1) = "Jason"
> > > >
> > > > newrow(2) = "1"
> > > >
> > > > dsTest.Tables(" TestTable").Row s.Add(newrow)
> > > >
> > > > dsTest.AcceptCh anges()
> > > >
> > > > End Sub
> > > >
> > > > Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
> > > > System.EventArg s) Handles Button1.Click
> > > >
> > > > Dim newrow As DataRow
> > > >
> > > > newrow = dsTest.Tables(" TestTable").New Row
> > > >
> > > > newrow(0) = "2"
> > > >
> > > > newrow(1) = "Jason"
> > > >
> > > > newrow(2) = "1"
> > > >
> > > > dsTest.Tables(" TestTable").Row s.Add(newrow)
> > > >
> > > > dsTest.AcceptCh anges()
> > > >
> > > > DataGrid1.DataB ind()
> > > >
> > > > End Sub
> > > >
> > > >
> > > >
> > > > When I click the button, I would have thought that the
datagrid would
> > keep
> > > > increasing with the values "2,", "Jason", "1", but it doesn't.
> > > >
> > > > I believe I have what is called a disconnected dataset, and I

need the
> > > user
> > > > to work on a dataset before they post the final values to the
server,
> > > hence
> > > > why I'm not using a SQL Adapter.
> > > >
> > > > Can someone PLEASE explain why the above won't work, and how

to work
> > with
> > > > disconnected datasets.
> > > >
> > > > TIA
> > > >
> > > >
> > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>



Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
488
by: RMG | last post by:
I use VS.net 2003 and VSS 6a. Whilst working on the network the integration between VS.net and VSS works perfectly. But when I open a project whilst disconnected from the network I get some problems. When I open a solution VS.net tells me it can't find the VSS database and gives me an option to "work disconnected". If I select this option VS.net gives me a msgbox titled "Microsoft Development Environment" with the
6
2952
by: Steve Jorgensen | last post by:
I keep having problems in which ADO disconnected recordset work under some circumstances, but lose all their data at other times, having no rows or fields, though the recordset object still exists. One case where this happened to me today was in trying to store disconnected recordsets in a cache collection in case they are needed again later in the same session. When I retrieve the recordset from the collection, it's empty. On the other...
3
2543
by: AC | last post by:
Running VS.NET 2003 Enterprise Arch on WinXP Pro SP1 with a P4-2.4Ghz, 760MB+ RAM, and 10+GB free disk space. Laptop is part of a domain. When working on a web project connected at the office, VS.NET enters into debug mode (compiling, firing off a browser, and starting the debugger) just fine. However, when the machine is disconnected, or I'm working off a wireless network @ home (WiFi) or working off a wired connection @ home (all...
2
2682
by: =?Utf-8?B?ZGdjb29wZXI=?= | last post by:
When I get a list of drives using the Directory.GetLogicalDrives(), it gives me all drives including disconnected network drives. When I attempt to use Directory.GetDirectories() on a disconnected drive, the GetDirectories Method stops responding. I also tried to use properties such as DirectoryInfo.Attributes but I have the same problem. How do I detect if one of the logical drives in my list is a disconnected network drive? I want to...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10387
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10120
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7662
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.