Solved

The type or namespace name 'DataRowView' could not be found (are you missing a using directive or an assembly reference?

Posted on 2010-08-13
13
2,322 Views
Last Modified: 2012-05-10
I am getting compile error in following file defaultPage.master
The type or namespace name 'DataRowView' could not be found (are you missing a using directive or an assembly reference?)C:\Projects\camsCSDev\camsCSData\defaultPage.master
Thanks in advance.
Complete code attached below:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="defaultPage.master.cs" Inherits="defaultPage" %>

<%@ Register Assembly="Tims2Objects" Namespace="Tims2Objects" TagPrefix="cc6" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head id="Head1" runat="server">

<title>CAMS2</title>

<style type="text/css">

.roundedcornr_box_160519 {

	background: url(../images2/roundedcornr_160519_tl.png) no-repeat top left;

}

.roundedcornr_top_160519 {

	background: url(../images2/roundedcornr_160519_tr.png) no-repeat top right;

}

.roundedcornr_bottom_160519 {

	background: url(../images2/roundedcornr_160519_bl.png) no-repeat bottom left;

}

.roundedcornr_bottom_160519 div {

	background: url(../images2/roundedcornr_160519_br.png) no-repeat bottom right;

}

.roundedcornr_content_160519 {

	background: url(../images2/roundedcornr_160519_r.png) top right repeat-y;

}

.roundedcornr_top_160519 div,.roundedcornr_top_160519,

.roundedcornr_bottom_160519 div, .roundedcornr_bottom_160519 {

	width: 100%;

	height: 15px;

	font-size: 1px;

}

.roundedcornr_content_160519, .roundedcornr_bottom_160519 {

	margin-top: -19px;

}

.roundedcornr_content_160519 { padding: 0 10px; }

.myfont {

		background-color : Transparent ;

		font-family : Arial, Helvetica, sans-serif;

		color : White ;

		font-size: xx-small;

		top :5px;

	}

</style>

<link rel="Stylesheet" href="./dirmenu/deluxe-css-menu.files/style.css" />

<asp:ContentPlaceHolder ID="head" runat="server">

        

        </asp:ContentPlaceHolder>

</head>

<body style="background-image: url(./dirmenu/WebFront.jpg); background-repeat:repeat-x">

<!--START PAGE SECTION-->

<form id="form1" runat="server" >

<div style=" position:absolute; top:0px; width:792px; height:38px; left:0px; background-color:Transparent; font-size:smaller; overflow:auto;  border: 0px solid #722F90;background-image:url('./Includes/images/bottom_menu_item_bg.png'); background-repeat:repeat-x;" 

    id="DIV1" >



<div style=" position:absolute; top:-14px; left:39px; height:38px; width:564px;font-size:smaller; overflow:auto;  border: 0px solid #722F90; right: 29px;"

id="DIV3" >   

<ul id="cssMenu">

<li><a href="./DefaultMasterPage.aspx?id=1"><span>Home</span></a></li>

<li><a href="./Schema_Alt.aspx"><span>Schema_Alt</span></a></li>

<li><a href="./Menu.aspx"><span>Menu</span></a></li>

<li><a href="./Template.aspx"><span>Display</span></a></li>

<li><a href="./admin/list.aspx"><span>Admin</span></a></li>

<li><a href="./FrontPage.aspx"><span>FrontPage</span></a></li>

</ul>





</div>



<span class="myfont" style="position:absolute; left:500px">

&nbsp;|&nbsp;

<asp:Label Id="lblrcount" RunAt="server" CssClass="myfont" />&nbsp;|&nbsp;

</span>



<asp:Repeater id="tblpages" runat="server">

<HeaderTemplate>

<table style="position:absolute; left:650px;" class="myfont"><tr>

</HeaderTemplate>

<AlternatingItemTemplate>

<td>



<a href="DefaultMasterPage.aspx?id=<%#((DataRowView)Container.DataItem)["id"] %>" title="DefaultMasterPage.aspx?id=<%#((DataRowView)Container.DataItem)["id"] %>" target="_self"><span class="myfont" >P:<%#((DataRowView)Container.DataItem)["id"] %></a></span>

</td>

</AlternatingItemTemplate>

<ItemTemplate>

<td>

<a href="DefaultMasterPage.aspx?id=<%#((DataRowView)Container.DataItem)["id"] %>" title="DefaultMasterPage.aspx?id=<%#((DataRowView)Container.DataItem)["id"] %>" target="_self"><span class="myfont" >P:<%#((DataRowView)Container.DataItem)["id"] %></a></span>

</td>

</ItemTemplate>

<FooterTemplate>

</tr></table>

</FooterTemplate>

</asp:Repeater>

</div>

<div id="DIV6" > 

<span class="myfont" style="position:absolute; width: 370px; left:420px;height:38px;font-size:smaller; overflow: hidden; ">

<cc6:TitleBlock6 ID="TitleBlock1" runat="server"  />

</span>

</div>

   <div style=" position:absolute; width:782px; height:114px; left:12px; top:38px; font-size:smaller; overflow:auto;  border: 0px solid #722F90; " 

    id="DIV4" >

        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        

        </asp:ContentPlaceHolder>

        <asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">

        

        </asp:ContentPlaceHolder>

        <asp:ContentPlaceHolder ID="ContentPlaceHolder3" runat="server">

        

        </asp:ContentPlaceHolder>

    </div>

    </form>

</body>

</html>

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Collections.Specialized;

using System.Data.SqlClient;

using System.Linq;

using System.Xml.Linq;

using System.Data.Common;

using System.IO;

using System.Text;

using System.Drawing;

using System.Data.OleDb;

using System.Globalization;

using System.Threading;

using System.Reflection;

using System.Web.SessionState;

using System.Web.Configuration;

using System.Collections.Generic;

using System.Text.RegularExpressions;

using System.Configuration;

using System;

using System.Data;

using System.Collections;

using System.Web;





public partial class defaultPage : System.Web.UI.MasterPage

{

    public string odbName;

    public string dbTableName;

    public string sDBName = "AdminDB2";

    public string TempTable = "tblPages";

    public string connectionString;

    public string MsgBoxDatabase = null;

    public string MsgBoxTable = null;

    public string MessageBox = null;

    public string MessageBoxProcedure = null;

    public bool bDatabaseExists = false;

    public bool bTableExists = false;

    public string strTable;

    public string strProcedure;

    public string server_tb;

    public string user_tb;

    public string pswrd_tb;

    public string database_tb;

    public string table_tb;

    protected ArrayList IDList = new ArrayList();

    protected bool DisplayChanged = false;

    // Table from which to retrieve records

    protected string TableName = "tblPages";

    // Primary key of table

    protected string PrimaryKeyColumn = "ID";

    // Default column by which records should be sorted

    protected string DefaultSortColumn = "pagename";

    // Names of columns to retrieve

    protected string ColumnsToRetrieve = "pagename,pagedata,homepage";

    //****************************************************

    protected void Page_Load(object sender, System.EventArgs e)

    {

        HttpContext _Context = HttpContext.Current;

        //lblhelp.Visible = False

        string query = "Select pagename,id,homepage FROM tblpages order by pagename;";

        //Dim myConn As New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbsource & "")

        //Dim Cmd As New OleDbCommand(query, myConn)

        SqlConnection myConn = new SqlConnection();

        myConn = new System.Data.SqlClient.SqlConnection(GetConnectionString(sDBName));

        SqlCommand Cmd = new SqlCommand(query, myConn);

        myConn.Open();

        //Dim dbread

        SqlDataReader dbread = null;

        dbread = Cmd.ExecuteReader();

        tblpages.DataSource = dbread;

        tblpages.DataBind();

        dbread.Close();

        myConn.Close();

        //if (System.Convert.ToInt32((int)(new Page().Session["InsertFlag"])) == 1)

        //string numberofresults = tblpages.Items.Count;

        string  numberofresults = "2";

        lblrcount.Text = numberofresults + " pages found";

        string idvalue = ID;

    }

    //****************************************************

    public static string GetConnectionString(string catalogName)

    {

        string connectionString = null;

        string connectionString2 = null;

        string MyString = null;

        string newVariable = ";uid=sa;pwd=h6web97;";

        string newVariable1 = "server=";

        string newVariable12 = "Initial Catalog=" + catalogName;

        string newVariable13 = ";Trusted_Connection=True";

        //connectionString = newVariable1 & System.Net.Dns.GetHostName() & "\" & newVariable & newVariable12 & newVariable13

        connectionString = newVariable1 + System.Net.Dns.GetHostName() + newVariable + newVariable12;

        //Return "Server=GRAHAMPC\SQLEXPRESS;Database=TIMS2;Trusted_Connection=True"

        return connectionString;

    }

    //****************************************************

    public static string GetConnectionString2()

    {

        string connectionString = null;

        string connectionString2 = null;

        string MyString = null;

        //Dim newVariable As String = "sqlexpress;uid=;pwd=;"

        string newVariable = ";uid=sa;pwd=h6web97;";

        string newVariable1 = "server=";

        //Dim newVariable12 As String = "Initial Catalog=" & catalogName

        string newVariable13 = "Trusted_Connection=True";

        //connectionString2 = newVariable1 & System.Net.Dns.GetHostName() & "\" & newVariable & newVariable13

        //connectionString2 = newVariable1 & System.Net.Dns.GetHostName() & "\" & newVariable

        connectionString2 = newVariable1 + System.Net.Dns.GetHostName() + newVariable;

        //Return "Server=GRAHAMPC\SQLEXPRESS;Database=TIMS2;Trusted_Connection=True"

        return connectionString2;

    }

    //****************************************************

    public static string MyString()

    {

        throw new Exception("The method or operation is not implemented.");

    }

    //****************************************************



    override protected void OnInit(EventArgs e)

    {

        base.OnInit(e);



        //INSTANT C# NOTE: Converted event handler wireups:

        this.Load += new System.EventHandler(Page_Load);

    }

}

Open in new window

0
Comment
Question by:homeshopper
  • 5
  • 5
  • 3
13 Comments
 
LVL 5

Expert Comment

by:almander
Comment Utility
Add System.Data to the front of references to DataRowView
0
 
LVL 5

Expert Comment

by:almander
Comment Utility
Also you can add the namesapce this way.

<%@ Import Namespace="System.Data " %>
0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
Comment Utility
Hi,

If your application is Single File Page model then almander's second answer is correct and if it Code Behind Page model then again almander's first solution is correct.

Regards,
VSS
0
 

Author Comment

by:homeshopper
Comment Utility
code now compiles, but when run gives new error:
Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Data.Common.DataRecordInternal' to type 'System.Data.DataRowView'.
Source Error:
Line 80: <ItemTemplate>
Line 81: <td>
Line 82: <a href="DefaultMasterPage.aspx?id=<%#((System.Data.DataRowView)Container.DataItem)["id"] %>" >P:</a>
Line 83: </td>
Line 84: </ItemTemplate>
Source File: c:\Projects\camsCSDev\camsCSData\defaultPage.master    Line: 82

<asp:Repeater id="tblpages" runat="server">
<HeaderTemplate>
<table style="position:absolute; left:2px;" class="myfont">
<tr>
</HeaderTemplate>
<AlternatingItemTemplate>
<td>

</td>
</AlternatingItemTemplate>
<ItemTemplate>
<td>
<a href="DefaultMasterPage.aspx?id=<%#((System.Data.DataRowView)Container.DataItem)["id"] %>" >P:</a>
</td>
</ItemTemplate>
<FooterTemplate>
</tr></table>
</FooterTemplate>
</asp:Repeater>
0
 

Author Comment

by:homeshopper
Comment Utility
for clarity I have attached complete code.
Thanks in advance.
defaultPageMasterCS.txt
0
 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 250 total points
Comment Utility
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:homeshopper
Comment Utility
I am trying to follow the method as suggested & code so far below:
still getting same error in line 146.
Line 144:        if (e.Item.ItemType == ListItemType.AlternatingItem | e.Item.ItemType == ListItemType.Item)
Line 145:        {
Line 146:            DataRowView dr = (DataRowView)e.Item.DataItem;
Line 147:        }
Line 148:
'*.aspx' code:
<asp:Repeater id="tblpages" runat="server"
 OnItemCreated="tblpages_ItemCreated">
<HeaderTemplate>
<table style="position:absolute; left:2px;" class="myfont">
<tr>
</HeaderTemplate>
<AlternatingItemTemplate>
<td>

</td>
</AlternatingItemTemplate>
<ItemTemplate>
<td>
<a href="DefaultMasterPage.aspx?id=<%#((System.Data.DataRowView)Container.DataItem)["id"] %>" >P:</a>
</td>
</ItemTemplate>
<FooterTemplate>
</tr></table>
</FooterTemplate>
</asp:Repeater>
'*.aspx.cs' code:
protected void Page_Load(object sender, System.EventArgs e)
    {
        HttpContext _Context = HttpContext.Current;
        //lblhelp.Visible = False
        string query = "Select pagename,id,homepage FROM tblpages order by pagename;";
        //Dim myConn As New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & dbsource & "")
        //Dim Cmd As New OleDbCommand(query, myConn)
        SqlConnection myConn = new SqlConnection();
        myConn = new System.Data.SqlClient.SqlConnection(GetConnectionString(sDBName));
        SqlCommand Cmd = new SqlCommand(query, myConn);
        myConn.Open();
        //Dim dbread
        SqlDataReader dbread = null;
        dbread = Cmd.ExecuteReader();
        //DataRowView dr = (DataRowView)e.Item.DataItem;
        tblpages.DataSource = dbread;
        tblpages.DataBind();
        dbread.Close();
        myConn.Close();
        //if (System.Convert.ToInt32((int)(new Page().Session["InsertFlag"])) == 1)
        //string numberofresults = tblpages.Items.Count;
        string  numberofresults = "2";
        lblrcount.Text = numberofresults + " pages found";
        string idvalue = ID;
    }
protected void tblpages_ItemCreated(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem | e.Item.ItemType == ListItemType.Item)
        {
            DataRowView dr = (DataRowView)e.Item.DataItem;
        }

    }
0
 
LVL 5

Expert Comment

by:almander
Comment Utility
What is in Container.DataItem is not a DataRowView, i is a datareader.

        //DataRowView dr = (DataRowView)e.Item.DataItem;
        tblpages.DataSource = dbread;

Try the code below in place of
((System.Data.DataRowView)Container.DataItem)["id"]
((System.Data.Common.DbDataRecord)Container.DataItem).GetString(1)

Open in new window

0
 

Author Comment

by:homeshopper
Comment Utility
Exception Details: System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'.
Source Error:
Line 92: <ItemTemplate>
Line 93: <td>
Line 94: <a href="DefaultMasterPage.aspx?id=<%#((System.Data.Common.DbDataRecord)Container.DataItem).GetString(1)%>" >P:</a>
Line 95: </td>
Line 96: </ItemTemplate>
Source File: c:\Projects\camsCSDev\camsCSData\defaultPage.master    Line: 94
0
 
LVL 5

Expert Comment

by:almander
Comment Utility
This is something that you may be running into a lot. Again this error is telling you that it the item cannot be implicitly converted to another type. If you consider what the error message says, and compare it with the change that was made, it makes perfect sense.

In this case, the error is telling you that the database field ID is an integer, and not a string.

You will need to choose the method for DbDataRecord that matches the datatype of ID. My first guess is .GetInt32 instead of .GetString

A list of methods can be found at http://msdn.microsoft.com/en-us/library/system.data.common.dbdatarecord_methods.aspx
0
 
LVL 5

Assisted Solution

by:almander
almander earned 250 total points
Comment Utility
If it is not obvious, with .GetString(1). The 1, corresponds to the position of ID, in your select statement.

string query = "Select pagename,id,homepage FROM tblpages order by pagename;";

Let us say that you wanted the homepage field, you would use (assuming that the datatype is a string type) .GetString(2)



       
0
 
LVL 16

Expert Comment

by:Vikram Singh Saini
Comment Utility
Hi,

I am just assuming that the piece of code should work. Otherwise almander is right.

Regards,
VSS

-----------
//Your Code
-----------
Line 94: <a href="DefaultMasterPage.aspx?id=<%#((System.Data.Common.DbDataRecord)Container.DataItem).GetString(1)%>" >P:</a>

----------------------
//Replace it with code
----------------------
Line 94: <a href="DefaultMasterPage.aspx?id=<%#((System.Data.Common.DbDataRecord)Container.DataItem).GetString("1")%>" >P:</a>

Open in new window

0
 

Author Comment

by:homeshopper
Comment Utility
Thanks Guys, I now have it working:
<span class="myfont" style="position:absolute; left:10px; top :0px;">
<a href="DefaultMasterPage.aspx?id=<%#((System.Data.Common.DbDataRecord)Container.DataItem).GetInt32(1)%>" >P:<%#((System.Data.Common.DbDataRecord)Container.DataItem).GetInt32(1)%></a>
</span>
I know understand the suggested methodolgy used.
The .NET Framework Class Library DbDataRecord Methods was also helpfull.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now