dataview

N

nicholas

think it's rather simple...but don't know how.

Showing bound data on a page is quite simple if you use a datagrid,
datalist, etc.

But I just want to put some databound items on my page, without datagrid,
etc.
(And there will be just 1 record selected, so no repeating problem)

So, here is what I did to connect to the database and select the appropriate
row:

####### code start #####

Sub Page_Load(sender As Object, e As EventArgs)

'Load all info from the database:

'define where the connectionstring is here:
Dim MyConnectionString as String =
ConfigurationSettings.AppSettings("ConnectionString")

'make the connection
Dim MyConnection as New SqlConnection(MyConnectionString)

'deine some variable needed for the SQL-string here:
Dim TheSelectedShopID as String = Request.QueryString("shopID")

'define the SQL-string here
Dim SQLstring As String
SQLstring = "SELECT * FROM tbl_shops WHERE shopID = " +
TheSelectedShopID

'create the DataAdapter
Dim MyAdapter As New SqlDataAdapter(SqlString, MyConnection)

'create and fill the datatable
Dim MyDataTable as new Datatable
MyAdapter.Fill(MyDataTable)

'create and fill the dataset
Dim MyDataSet as new Dataset
MyAdapter.Fill(MyDataSet)

'create dataview
Dim MyView as DataView = MyDataSet.tables(0).defaultview

End Sub

############# end of code ########

So now, in my html code I would like to place something like this:

the name of the shop is <%# MyView.FieldValue("shopnameEN", Container) %>

But I get an error saying that MyView is not declared.

Must do something wrong here..?

btw. the connection works.
because if I use this it works:

######
'select the row in the datatable
Dim CurrentRow As DataRow
CurrentRow = myDataTable.Rows(0)

'set the texts in the page to the content of the datarow
shopname.text = CurrentRow("shopnameEN")
#####

But I don't want to do it this way...

THX for advice.
Nic
 
M

Michael Tkachev

Hi,

You cannot use "<%#" without datagrid control. If you want to show a result,
you have to use a datagrid or labels.

If you will be using a datagrid, you can hide borders and header or
something like this. therefore you will get just result. Also you can use
labels and then use sqldatareader.

SqlCommand cmd = new SqlCommand("your command", new sqlConnection("Your
connection String"));
cmd.Connection.Open();
SqlDatareader dr = cmd.ExecuteNonQuery(CommandBehavior.CloseConnection);
if(dr.Read())
{
label1.Text = dr[columnName or ColumnNeumber].ToString();
... etc
}
dr.Close();

This code shows you how you can show a result without datagrid.


Bye
 
N

nicholas

OK.

Let's say I use a Datatable and set for example my shopname this way:
shopname.text = CurrentRow("shopnameEN")
(I tried this and it works.)

Now, how could I set the background image of a table to
CurrentRow("shopImage") ??

THX

Michael Tkachev said:
Hi,

You cannot use "<%#" without datagrid control. If you want to show a result,
you have to use a datagrid or labels.

If you will be using a datagrid, you can hide borders and header or
something like this. therefore you will get just result. Also you can use
labels and then use sqldatareader.

SqlCommand cmd = new SqlCommand("your command", new sqlConnection("Your
connection String"));
cmd.Connection.Open();
SqlDatareader dr = cmd.ExecuteNonQuery(CommandBehavior.CloseConnection);
if(dr.Read())
{
label1.Text = dr[columnName or ColumnNeumber].ToString();
... etc
}
dr.Close();

This code shows you how you can show a result without datagrid.


Bye


nicholas said:
think it's rather simple...but don't know how.

Showing bound data on a page is quite simple if you use a datagrid,
datalist, etc.

But I just want to put some databound items on my page, without datagrid,
etc.
(And there will be just 1 record selected, so no repeating problem)

So, here is what I did to connect to the database and select the appropriate
row:

####### code start #####

Sub Page_Load(sender As Object, e As EventArgs)

'Load all info from the database:

'define where the connectionstring is here:
Dim MyConnectionString as String =
ConfigurationSettings.AppSettings("ConnectionString")

'make the connection
Dim MyConnection as New SqlConnection(MyConnectionString)

'deine some variable needed for the SQL-string here:
Dim TheSelectedShopID as String = Request.QueryString("shopID")

'define the SQL-string here
Dim SQLstring As String
SQLstring = "SELECT * FROM tbl_shops WHERE shopID = " +
TheSelectedShopID

'create the DataAdapter
Dim MyAdapter As New SqlDataAdapter(SqlString, MyConnection)

'create and fill the datatable
Dim MyDataTable as new Datatable
MyAdapter.Fill(MyDataTable)

'create and fill the dataset
Dim MyDataSet as new Dataset
MyAdapter.Fill(MyDataSet)

'create dataview
Dim MyView as DataView = MyDataSet.tables(0).defaultview

End Sub

############# end of code ########

So now, in my html code I would like to place something like this:

the name of the shop is <%# MyView.FieldValue("shopnameEN", Container) %>

But I get an error saying that MyView is not declared.

Must do something wrong here..?

btw. the connection works.
because if I use this it works:

######
'select the row in the datatable
Dim CurrentRow As DataRow
CurrentRow = myDataTable.Rows(0)

'set the texts in the page to the content of the datarow
shopname.text = CurrentRow("shopnameEN")
#####

But I don't want to do it this way...

THX for advice.
Nic
 
N

nicholas

problem solved.

I used an ASP table, so that I can set every property of that table.

THX

nicholas said:
OK.

Let's say I use a Datatable and set for example my shopname this way:
shopname.text = CurrentRow("shopnameEN")
(I tried this and it works.)

Now, how could I set the background image of a table to
CurrentRow("shopImage") ??

THX

Michael Tkachev said:
Hi,

You cannot use "<%#" without datagrid control. If you want to show a result,
you have to use a datagrid or labels.

If you will be using a datagrid, you can hide borders and header or
something like this. therefore you will get just result. Also you can use
labels and then use sqldatareader.

SqlCommand cmd = new SqlCommand("your command", new sqlConnection("Your
connection String"));
cmd.Connection.Open();
SqlDatareader dr = cmd.ExecuteNonQuery(CommandBehavior.CloseConnection);
if(dr.Read())
{
label1.Text = dr[columnName or ColumnNeumber].ToString();
... etc
}
dr.Close();

This code shows you how you can show a result without datagrid.


Bye


nicholas said:
think it's rather simple...but don't know how.

Showing bound data on a page is quite simple if you use a datagrid,
datalist, etc.

But I just want to put some databound items on my page, without datagrid,
etc.
(And there will be just 1 record selected, so no repeating problem)

So, here is what I did to connect to the database and select the appropriate
row:

####### code start #####

Sub Page_Load(sender As Object, e As EventArgs)

'Load all info from the database:

'define where the connectionstring is here:
Dim MyConnectionString as String =
ConfigurationSettings.AppSettings("ConnectionString")

'make the connection
Dim MyConnection as New SqlConnection(MyConnectionString)

'deine some variable needed for the SQL-string here:
Dim TheSelectedShopID as String = Request.QueryString("shopID")

'define the SQL-string here
Dim SQLstring As String
SQLstring = "SELECT * FROM tbl_shops WHERE shopID = " +
TheSelectedShopID

'create the DataAdapter
Dim MyAdapter As New SqlDataAdapter(SqlString, MyConnection)

'create and fill the datatable
Dim MyDataTable as new Datatable
MyAdapter.Fill(MyDataTable)

'create and fill the dataset
Dim MyDataSet as new Dataset
MyAdapter.Fill(MyDataSet)

'create dataview
Dim MyView as DataView = MyDataSet.tables(0).defaultview

End Sub

############# end of code ########

So now, in my html code I would like to place something like this:

the name of the shop is <%# MyView.FieldValue("shopnameEN", Container) %>

But I get an error saying that MyView is not declared.

Must do something wrong here..?

btw. the connection works.
because if I use this it works:

######
'select the row in the datatable
Dim CurrentRow As DataRow
CurrentRow = myDataTable.Rows(0)

'set the texts in the page to the content of the datarow
shopname.text = CurrentRow("shopnameEN")
#####

But I don't want to do it this way...

THX for advice.
Nic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top