Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx_beginners thread: DataView


Message #1 by "F-J Mattmann" <f-j.mattmann@e...> on Sun, 21 Jul 2002 16:52:58
Hi,
I want to look at my uselist DataTable through different Dataviews, I 
thought it just was to replace the line:

MyDataGrid.DataSource=ds.Tables("userlist").Defaultview
with:
MyDataGrid.DataSource=ds.Tables("userlist").Myview

but it doesnīt seem to work that way, I am of course, missunderstanding 
something, can anyone tell me what? 
Thank you in advance.

here is my code:
------------------------------------------------------------------

Sub page_load(Sender As Object, E As EventArgs) 

	
        Dim DS As new DataSet
	
	Dim MyConnection As SqlConnection
	MyConnection = New SqlConnection
("server=SARA;database=intraDB;UID=sa")
         	 
	Dim MyCommand  As SqlDataAdapter
	MyCommand  = New SqlDataAdapter("select* from tblusers WHERE 
Firstname='Maria' OR Firstname='Roger'", MyConnection)

	MyCommand.Fill(ds, "userlist")
	
	Dim DTuserlist as DataTable = ds.Tables("userlist")
	
                Dim MyView as new DataView(DTuserlist)
	MyView.RowStateFilter = DataViewRowState.ModifiedOriginal
	MyView.Sort = "Firstname ASC"
      

	           MyDataGrid.DataSource=ds.Tables("userlist").Defaultview
    ''''' not working: MyDataGrid.DataSource=ds.Tables("userlist").Myview
	
               MyDataGrid.DataBind()

	MyConnection.Close()


  End Sub
Message #2 by "F-J Mattmann" <f-j.mattmann@e...> on Mon, 22 Jul 2002 14:54:43
Hi again
I solved my problem with the code below, but now my problem is that I can 
not use "RowFilter" to fetch only the row which contains "Monica" in 
the "Firstname"-column.
When I activated the line: 
Minvy1.Rowfilter ="Firstname = Monica" it Does not work because it 
understands Monica as a column!!!!!
What is wrong?
Thanks in advance for any help!
//F-J
------------------------------------
Here is my code:
------------------------------------
<%@ Page Language="VB" Debug="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script language="VB" runat="server">

 Public Sub Page_Load(Sender As System.Object, E As System.EventArgs)
        dim ds as new DataSet("MittDataSet")
	Dim MyConnection As SqlConnection
	MyConnection = New SqlConnection
("server=SARA;database=intraDB;UID=sa")
        Dim MyCommand  As SqlDataAdapter
	MyCommand  = New SqlDataAdapter("SELECT TOP 5 * FROM 
tblusers",MyConnection)

MyCommand.Fill(ds,"Mintabell")

dim dTable as new DataTable("MinTabell")
dim MyRows() as DataRow = ds.Tables("MinTabell").Select
(Nothing, "Firstname", DataViewRowState.CurrentRows)

dim MinVy1 = new System.Data.DataView(ds.Tables(0))
Minvy1.Sort = "Firstname ASC"

'Minvy1.Rowfilter ="Firstname = Monica"  
''Does not work!! understand Monica as a column!!!!!

Grid1.DataSource = minvy1
grid1.databind

MyConnection.Close()

End Sub

</script>

<HTML><BODY>
  <asp:DataGrid id="Grid1" runat="server" />
</body></HTML>



Message #3 by "F-J Mattmann" <f-j.mattmann@e...> on Tue, 23 Jul 2002 06:35:31
Hi thatīs me again, I now understand my problem, just replace the line:

Minvy1.Rowfilter ="Firstname = Monica"
with:

Minvy1.Rowfilter ="Firstname = 'Monica'"

(pay attention to the quotest around Monica)
simple, but very tricky for me. I hope This eventualy can help a beginner 
like me?


  Return to Index