|
What is the best way to keep data between pages (data can be change) and at the end submitted to the SQL database?
can you give me an example? Thanks
|
|
|
There are many ways to keep data of pages, the most simple way is as below
U can keep data with session variables for example
i want to a numeric value 2
Session.item("myValue",2)
and in nex page i can get it like below
Dim sessionvalue as Integer
sessionvalue =Session.item("myValue")
<Added>
in above lines i miss session.add in 4th line sorry
There are many ways to keep data of pages, the most simple way is as below
U can keep data with session variables for example
i want to a numeric value 2
Session.Add("myValue",2)
and in next page i can get it like below
Dim sessionvalue as Integer
sessionvalue =Session.item("myValue")
|
|
|
what about keeping dataset in session?
I have a user control on a first page with text boxes and I am thinking to put all data in ds, but I don't know how. Do you have an example how to do this? Thanks
|
|
|
First i dont know y u need dataset to keep values of textboxes, however u keep dataset in session like below.
session.add("SessionVariableName",DatasetName)
and u can get values of dataset like below
dim mydataset as Dataset=Ctype(Session.item("SessionVariableName"),DataSet)
dim myvalue =mydataset.tables(0).Rows(0).Item("NameofItem")
U can also iterate all dataset using for or foe each loop.
2nd Solution
============
If u want to keep values of ur 2 textboxes in user control write below 2 lines in ur user control.
Session.add("1stTextBoxValue",TextBox1.Text)
Session.add("2ndTextBoxValue",TextBox2.Text)
And in required page u can get ur textboxes values like below
Dim firstvalue as String=Session.item("1stTextBoxValue")
Dim secondvalue as String=Session.item("2ndTextBoxValue")
<Added>
Mistake
=======
U can also iterate all dataset using for or for each loop.
|
|
|
What I am trying to do is to submit a dataset to a sql instead of separate value for each box.
|
|
|
first import Namespace in top of ur page
Imports System.Data.SqlClient
then write below code in ur required event it will pull all the the data in to SQL server
Dim myConn As New SqlConnection("ur Connection string")
myConn.Open()
Dim myCom As SqlCommand = myConn.CreateCommand()
myCom.CommandText = "Insert Into tablename(istfirld,2ndField) values('" + session.Item("istValue+"','"+ Session.item("senondValue")+"')"
myCom.ExecuteNonQuery()
myConn.Close()
|
|
|