Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > dataview

Reply
Thread Tools

dataview

 
 
nicholas
Guest
Posts: n/a
 
      10-07-2004
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("ConnectionStrin g")

'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


 
Reply With Quote
 
 
 
 
Michael Tkachev
Guest
Posts: n/a
 
      10-07-2004
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.CloseConnectio n);
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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("ConnectionStrin g")
>
> '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
>
>



 
Reply With Quote
 
 
 
 
nicholas
Guest
Posts: n/a
 
      10-07-2004
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" <(E-Mail Removed)> wrote in message
news:%236$(E-Mail Removed)...
> 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.CloseConnectio n);
> 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" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > 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("ConnectionStrin g")
> >
> > '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
> >
> >

>
>



 
Reply With Quote
 
nicholas
Guest
Posts: n/a
 
      10-07-2004
problem solved.

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

THX

"nicholas" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:%236$(E-Mail Removed)...
> > 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.CloseConnectio n);
> > 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" <(E-Mail Removed)> wrote in message
> > news:%(E-Mail Removed)...
> > > 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("ConnectionStrin g")
> > >
> > > '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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorted DataView, but unsorted datalist when bound to the dataview CodeMonkey ASP .Net 1 02-04-2011 10:55 AM
DataView.RowFilter doesn't work jacksu MCSD 5 04-20-2007 12:43 AM
DataTable and DataView Ruslan ASP .Net 3 10-30-2003 10:26 AM
Query on DataView.Sort Property Denzil ASP .Net 1 10-22-2003 11:01 PM
Re: non-unique indexes / dataview William \(Bill\) Vaughn ASP .Net 3 07-17-2003 12:33 AM



Advertisments