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
ip()
If Not IsPostBack Then
DataGrid1.DataBind()
End If
End Sub
Sub ip()
Dim newrow As DataRow
SqlConnection1.Open()
SqlCommand1.Parameters("@members").Value = "1007,4200,999"
daTest.SelectCommand = SqlCommand1
daTest.Fill(dsTest, "TestTable")
Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "",
DataViewRowState.CurrentRows)
DataGrid1.DataSource = dvTest
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "1"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim newrow As DataRow
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "2"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
DataGrid1.DataBind()
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 5 1026
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**************@tk2msftngp13.phx.gbl... 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
ip()
If Not IsPostBack Then
DataGrid1.DataBind()
End If
End Sub
Sub ip()
Dim newrow As DataRow
SqlConnection1.Open()
SqlCommand1.Parameters("@members").Value = "1007,4200,999"
daTest.SelectCommand = SqlCommand1
daTest.Fill(dsTest, "TestTable")
Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "", DataViewRowState.CurrentRows)
DataGrid1.DataSource = dvTest
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "1"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newrow As DataRow
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "2"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
DataGrid1.DataBind()
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
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*****@aboutfortunate.com> wrote in message
news:uU**************@tk2msftngp13.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**************@tk2msftngp13.phx.gbl... 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
ip()
If Not IsPostBack Then
DataGrid1.DataBind()
End If
End Sub
Sub ip()
Dim newrow As DataRow
SqlConnection1.Open()
SqlCommand1.Parameters("@members").Value = "1007,4200,999"
daTest.SelectCommand = SqlCommand1
daTest.Fill(dsTest, "TestTable")
Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "", DataViewRowState.CurrentRows)
DataGrid1.DataSource = dvTest
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "1"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newrow As DataRow
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "2"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
DataGrid1.DataBind()
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
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") '***********Move this (It should only be done on
post back)
If Not IsPostBack Then
ip() '*******Moved here.
DataGrid1.DataBind()
Else
dsTest = Session("Temp")
End If
End Sub
Sub ip()
Dim newrow As DataRow
SqlConnection1.Open()
SqlCommand1.Parameters("@members").Value = "1007,4200,999"
daTest.SelectCommand = SqlCommand1
daTest.Fill(dsTest, "TestTable")
Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "",
DataViewRowState.CurrentRows)
DataGrid1.DataSource = dvTest
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "1"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
Session("Temp") = dsTest '*********Add the datatable to the session
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim newrow As DataRow
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "2"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
Session("Temp") = dsTest.Tables("TestTable")
DataGrid1.DataBind()
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**************@TK2MSFTNGP10.phx.gbl... Well My code now looks like...
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
ip()
dsTest = Session("Temp")
If Not IsPostBack Then
DataGrid1.DataBind()
End If
End Sub
Sub ip()
Dim newrow As DataRow
SqlConnection1.Open()
SqlCommand1.Parameters("@members").Value = "1007,4200,999"
daTest.SelectCommand = SqlCommand1
daTest.Fill(dsTest, "TestTable")
Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "", DataViewRowState.CurrentRows)
DataGrid1.DataSource = dvTest
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "1"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newrow As DataRow
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "2"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
Session("Temp") = dsTest.Tables("TestTable")
DataGrid1.DataBind()
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.NullReferenceException: Object reference not set to an instance of an object.
Source Error: Line 74: Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click Line 75: Dim newrow As DataRow Line 76: newrow = dsTest.Tables("TestTable").NewRow Line 77: newrow(0) = "2" Line 78: newrow(1) = "Jason"
Source File: c:\inetpub\wwwroot\hbitl_umc\test.aspx.vb Line: 76
Am I really doing this right?
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message news:#k**************@TK2MSFTNGP09.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*************@tk2msftngp13.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*****@aboutfortunate.com> wrote in message news:uU**************@tk2msftngp13.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**************@tk2msftngp13.phx.gbl... > > 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 > > > > ip() > > > > If Not IsPostBack Then > > > > DataGrid1.DataBind() > > > > End If > > > > End Sub > > > > Sub ip() > > > > Dim newrow As DataRow > > > > > > > > > > > > SqlConnection1.Open() > > > > SqlCommand1.Parameters("@members").Value = "1007,4200,999" > > > > daTest.SelectCommand = SqlCommand1 > > > > daTest.Fill(dsTest, "TestTable") > > > > Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "", > > DataViewRowState.CurrentRows) > > > > DataGrid1.DataSource = dvTest > > > > newrow = dsTest.Tables("TestTable").NewRow > > > > newrow(0) = "1" > > > > newrow(1) = "Jason" > > > > newrow(2) = "1" > > > > dsTest.Tables("TestTable").Rows.Add(newrow) > > > > dsTest.AcceptChanges() > > > > End Sub > > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As > > System.EventArgs) Handles Button1.Click > > > > Dim newrow As DataRow > > > > newrow = dsTest.Tables("TestTable").NewRow > > > > newrow(0) = "2" > > > > newrow(1) = "Jason" > > > > newrow(2) = "1" > > > > dsTest.Tables("TestTable").Rows.Add(newrow) > > > > dsTest.AcceptChanges() > > > > DataGrid1.DataBind() > > > > 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 > > > > > > > > > > > >
Well, I've changed the code accordingly, it now looks like...
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
ip()
DataGrid1.DataBind()
Else
dsTest = Session("Temp")
End If
End Sub
Sub ip()
Dim newrow As DataRow
SqlConnection1.Open()
SqlCommand1.Parameters("@members").Value = "1007,4200,9999"
daTest.SelectCommand = SqlCommand1
daTest.Fill(dsTest, "TestTable")
Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "",
DataViewRowState.CurrentRows)
DataGrid1.DataSource = dvTest
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "1"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
Session("Temp") = dsTest
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim newrow As DataRow
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "2"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
Session("Temp") = dsTest.Tables("TestTable")
DataGrid1.DataBind()
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.InvalidCastException: Specified cast is not valid.
Source Error:
Line 49: DataGrid1.DataBind()
Line 50: Else
Line 51: dsTest = Session("Temp")
Line 52: End If
Line 53:
Source File: c:\inetpub\wwwroot\hbitl_umc\test.aspx.vb Line: 51
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:#E**************@TK2MSFTNGP10.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") '***********Move this (It should only be done on post back)
If Not IsPostBack Then
ip() '*******Moved here.
DataGrid1.DataBind()
Else
dsTest = Session("Temp")
End If
End Sub
Sub ip()
Dim newrow As DataRow
SqlConnection1.Open()
SqlCommand1.Parameters("@members").Value = "1007,4200,999"
daTest.SelectCommand = SqlCommand1
daTest.Fill(dsTest, "TestTable")
Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "", DataViewRowState.CurrentRows)
DataGrid1.DataSource = dvTest
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "1"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
Session("Temp") = dsTest '*********Add the datatable to the session
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newrow As DataRow
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "2"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
Session("Temp") = dsTest.Tables("TestTable")
DataGrid1.DataBind()
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**************@TK2MSFTNGP10.phx.gbl... Well My code now looks like...
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
ip()
dsTest = Session("Temp")
If Not IsPostBack Then
DataGrid1.DataBind()
End If
End Sub
Sub ip()
Dim newrow As DataRow
SqlConnection1.Open()
SqlCommand1.Parameters("@members").Value = "1007,4200,999"
daTest.SelectCommand = SqlCommand1
daTest.Fill(dsTest, "TestTable")
Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "", DataViewRowState.CurrentRows)
DataGrid1.DataSource = dvTest
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "1"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newrow As DataRow
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "2"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
Session("Temp") = dsTest.Tables("TestTable")
DataGrid1.DataBind()
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.NullReferenceException: Object reference not
set to an instance of an object.
Source Error: Line 74: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Line 75: Dim newrow As DataRow Line 76: newrow = dsTest.Tables("TestTable").NewRow Line 77: newrow(0) = "2" Line 78: newrow(1) = "Jason"
Source File: c:\inetpub\wwwroot\hbitl_umc\test.aspx.vb Line: 76
Am I really doing this right?
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message news:#k**************@TK2MSFTNGP09.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*************@tk2msftngp13.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*****@aboutfortunate.com> wrote in message > news:uU**************@tk2msftngp13.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**************@tk2msftngp13.phx.gbl... > > > 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 > > > > > > ip() > > > > > > If Not IsPostBack Then > > > > > > DataGrid1.DataBind() > > > > > > End If > > > > > > End Sub > > > > > > Sub ip() > > > > > > Dim newrow As DataRow > > > > > > > > > > > > > > > > > > SqlConnection1.Open() > > > > > > SqlCommand1.Parameters("@members").Value = "1007,4200,999" > > > > > > daTest.SelectCommand = SqlCommand1 > > > > > > daTest.Fill(dsTest, "TestTable") > > > > > > Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "", > > > DataViewRowState.CurrentRows) > > > > > > DataGrid1.DataSource = dvTest > > > > > > newrow = dsTest.Tables("TestTable").NewRow > > > > > > newrow(0) = "1" > > > > > > newrow(1) = "Jason" > > > > > > newrow(2) = "1" > > > > > > dsTest.Tables("TestTable").Rows.Add(newrow) > > > > > > dsTest.AcceptChanges() > > > > > > End Sub > > > > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As > > > System.EventArgs) Handles Button1.Click > > > > > > Dim newrow As DataRow > > > > > > newrow = dsTest.Tables("TestTable").NewRow > > > > > > newrow(0) = "2" > > > > > > newrow(1) = "Jason" > > > > > > newrow(2) = "1" > > > > > > dsTest.Tables("TestTable").Rows.Add(newrow) > > > > > > dsTest.AcceptChanges() > > > > > > DataGrid1.DataBind() > > > > > > 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 > > > > > > > > > > > > > > > > > > > > >
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**************@TK2MSFTNGP09.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.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
ip()
DataGrid1.DataBind()
Else
dsTest = Session("Temp")
End If
End Sub
Sub ip()
Dim newrow As DataRow
SqlConnection1.Open()
SqlCommand1.Parameters("@members").Value = "1007,4200,9999"
daTest.SelectCommand = SqlCommand1
daTest.Fill(dsTest, "TestTable")
Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "", DataViewRowState.CurrentRows)
DataGrid1.DataSource = dvTest
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "1"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
Session("Temp") = dsTest
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newrow As DataRow
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "2"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
Session("Temp") = dsTest.Tables("TestTable")
DataGrid1.DataBind()
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.InvalidCastException: Specified cast is not
valid. Source Error: Line 49: DataGrid1.DataBind() Line 50: Else Line 51: dsTest = Session("Temp") Line 52: End If Line 53:
Source File: c:\inetpub\wwwroot\hbitl_umc\test.aspx.vb Line: 51
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message news:#E**************@TK2MSFTNGP10.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") '***********Move this (It should only be done
on post back)
If Not IsPostBack Then
ip() '*******Moved here.
DataGrid1.DataBind()
Else
dsTest = Session("Temp")
End If
End Sub
Sub ip()
Dim newrow As DataRow
SqlConnection1.Open()
SqlCommand1.Parameters("@members").Value = "1007,4200,999"
daTest.SelectCommand = SqlCommand1
daTest.Fill(dsTest, "TestTable")
Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "", DataViewRowState.CurrentRows)
DataGrid1.DataSource = dvTest
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "1"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
Session("Temp") = dsTest '*********Add the datatable to the session
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newrow As DataRow
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "2"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
Session("Temp") = dsTest.Tables("TestTable")
DataGrid1.DataBind()
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**************@TK2MSFTNGP10.phx.gbl... Well My code now looks like...
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
ip()
dsTest = Session("Temp")
If Not IsPostBack Then
DataGrid1.DataBind()
End If
End Sub
Sub ip()
Dim newrow As DataRow
SqlConnection1.Open()
SqlCommand1.Parameters("@members").Value = "1007,4200,999"
daTest.SelectCommand = SqlCommand1
daTest.Fill(dsTest, "TestTable")
Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "", DataViewRowState.CurrentRows)
DataGrid1.DataSource = dvTest
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "1"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newrow As DataRow
newrow = dsTest.Tables("TestTable").NewRow
newrow(0) = "2"
newrow(1) = "Jason"
newrow(2) = "1"
dsTest.Tables("TestTable").Rows.Add(newrow)
dsTest.AcceptChanges()
Session("Temp") = dsTest.Tables("TestTable")
DataGrid1.DataBind()
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.NullReferenceException: Object reference not set to an instance of an object.
Source Error: Line 74: Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click Line 75: Dim newrow As DataRow Line 76: newrow = dsTest.Tables("TestTable").NewRow Line 77: newrow(0) = "2" Line 78: newrow(1) = "Jason"
Source File: c:\inetpub\wwwroot\hbitl_umc\test.aspx.vb Line: 76
Am I really doing this right?
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message news:#k**************@TK2MSFTNGP09.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*************@tk2msftngp13.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*****@aboutfortunate.com> wrote in message > > news:uU**************@tk2msftngp13.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**************@tk2msftngp13.phx.gbl... > > > > 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 > > > > > > > > ip() > > > > > > > > If Not IsPostBack Then > > > > > > > > DataGrid1.DataBind() > > > > > > > > End If > > > > > > > > End Sub > > > > > > > > Sub ip() > > > > > > > > Dim newrow As DataRow > > > > > > > > > > > > > > > > > > > > > > > > SqlConnection1.Open() > > > > > > > > SqlCommand1.Parameters("@members").Value = "1007,4200,999" > > > > > > > > daTest.SelectCommand = SqlCommand1 > > > > > > > > daTest.Fill(dsTest, "TestTable") > > > > > > > > Dim dvTest As New DataView(dsTest.Tables("TestTable"), "", "", > > > > DataViewRowState.CurrentRows) > > > > > > > > DataGrid1.DataSource = dvTest > > > > > > > > newrow = dsTest.Tables("TestTable").NewRow > > > > > > > > newrow(0) = "1" > > > > > > > > newrow(1) = "Jason" > > > > > > > > newrow(2) = "1" > > > > > > > > dsTest.Tables("TestTable").Rows.Add(newrow) > > > > > > > > dsTest.AcceptChanges() > > > > > > > > End Sub > > > > > > > > Private Sub Button1_Click(ByVal sender As System.Object, ByVal
e As > > > > System.EventArgs) Handles Button1.Click > > > > > > > > Dim newrow As DataRow > > > > > > > > newrow = dsTest.Tables("TestTable").NewRow > > > > > > > > newrow(0) = "2" > > > > > > > > newrow(1) = "Jason" > > > > > > > > newrow(2) = "1" > > > > > > > > dsTest.Tables("TestTable").Rows.Add(newrow) > > > > > > > > dsTest.AcceptChanges() > > > > > > > > DataGrid1.DataBind() > > > > > > > > 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 > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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....
|
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,...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |