dataview

Discussion in 'ASP .Net' started by nicholas, Oct 7, 2004.

  1. nicholas

    nicholas Guest

    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
     
    nicholas, Oct 7, 2004
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:%...
    > 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
    >
    >
     
    Michael Tkachev, Oct 7, 2004
    #2
    1. Advertising

  3. nicholas

    nicholas Guest

    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" <> wrote in message
    news:%236$...
    > 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" <> wrote in message
    > news:%...
    > > 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
    > >
    > >

    >
    >
     
    nicholas, Oct 7, 2004
    #3
  4. nicholas

    nicholas Guest

    problem solved.

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

    THX

    "nicholas" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:%236$...
    > > 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" <> wrote in message
    > > news:%...
    > > > 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
    > > >
    > > >

    > >
    > >

    >
    >
     
    nicholas, Oct 7, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. William \(Bill\) Vaughn

    Re: non-unique indexes / dataview

    William \(Bill\) Vaughn, Jul 16, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    1,761
    jai hanuman
    Jul 17, 2003
  2. Denzil

    Query on DataView.Sort Property

    Denzil, Oct 21, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,295
    Chris Taylor
    Oct 23, 2003
  3. Ruslan

    DataTable and DataView

    Ruslan, Oct 29, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    14,090
  4. Nathan Baulch
    Replies:
    0
    Views:
    1,946
    Nathan Baulch
    Jun 26, 2003
  5. CodeMonkey
    Replies:
    1
    Views:
    769
    joyal jhaveri
    Feb 4, 2011
Loading...

Share This Page