Print Page | Close Window

Problem with C# Code

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=13422
Printed Date: 28 March 2026 at 11:57am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Problem with C# Code
Posted By: Misty
Subject: Problem with C# Code
Date Posted: 19 January 2005 at 2:02pm
I am having a problem with my code in C#. It is possible that I have made a typo somewhere. It worked fine in VB.Net.
 
I am getting the following error message:
Compiler Error Message: CS0117: 'System.Web.UI.WebControls.DataList' does not contain a definition for 'Datasource'

Source Error:

Line 149:   	ds.Relations.Add("myrelation", ds.Tables["Area"].Columns["AreaID"], ds.Tables["SpaStore"].Columns["AreaID"]);
Line 150:
Line 151:	dlArea.Datasource = ds.Tables("Area").DefaultView;
Line 152:	DataBind();
 
Here's my code that is significant:

        //Get incoming querystring values
        string strChosenState = Request.QueryString["State"];
 
string MySQL  = "Select * from SpaStore INNER JOIN Area ON SpaStore.AreaID = Area.AreaID where Area.State = '" + strChosenState + "' AND ListingType IN ('Featured','National') AND Approve = 1 ORDER by SpaStoreName";

        SqlConnection MyConn = new SqlConnection(strConn);
        DataSet ds = new DataSet();
 
 SqlDataAdapter Cmd = new SqlDataAdapter(MySQL, MyConn);
        Cmd.Fill(ds, "SpaStore"); 
    
    
string mySQL2 = "Select Area.AreaID, AreaName from Area Inner Join SpaStore ON Area.AreaID = SpaStore.AreaID where Area.State = '" + strChosenState + "' AND ListingType IN ('Featured','National') AND Approve = 1 Group By Area.AreaID, AreaName Order by AreaName";

    SqlDataAdapter cmd2 = new SqlDataAdapter(mySQL2, MyConn);
    cmd2.Fill(ds, "Area");
 
    ds.Relations.Add("myrelation", ds.Tables["Area"].Columns["AreaID"], ds.Tables["SpaStore"].Columns["AreaID"]);
 dlArea.Datasource = ds.Tables("Area").DefaultView;
 DataBind();
 
 
 



Replies:
Posted By: Mart
Date Posted: 19 January 2005 at 2:22pm
C# is case sensitive... I.e. Datasource is different to DataSource... change that line to

dlArea.DataSource = ds.Tables("Area").DefaultView;



Posted By: Misty
Date Posted: 19 January 2005 at 2:30pm
I changed the code. I know that C# is case sensitive. For example, it would not let me use SQLConnection. I had to use SqlConnection.
 
There is still something wrong with this code because I'm getting the following error message now:
Compiler Error Message: CS0118: 'System.Data.DataSet.Tables' denotes a 'property' where a 'method' was expected

Source Error:

Line 149:   	ds.Relations.Add("myrelation", ds.Tables["Area"].Columns["AreaID"], ds.Tables["SpaStore"].Columns["AreaID"]);
Line 150:
Line 151:	dlArea.DataSource = ds.Tables("Area").DefaultView;


Posted By: Mart
Date Posted: 19 January 2005 at 2:33pm
You need

dlArea.DataSource = ds.Tables["Area"].DefaultView;



Posted By: Misty
Date Posted: 19 January 2005 at 2:56pm
I am getting another error message that has something to do with DataItem. Maybe DataItem is not the way I put in VB.Net. The error message is: CS0118: 'System.Web.UI.WebControls.DataListItem.DataItem' denotes a 'property' where a 'method' was expected.
 
There's something wrong with this line of code: <%# Container.DataItem("AreaName")%>

I tried using ["AreaName], but it didn't work. I am obviously missing something. Can someone please help me with this? Thanks!



Posted By: Mart
Date Posted: 19 January 2005 at 3:02pm
Try this:

<%# DataBinder.Eval(Container, "DataItem.AreaName") %>


Posted By: Misty
Date Posted: 20 January 2005 at 1:05am
I have another problem in C#. It worked fine in VB.Net. Unhappy For some reason, C# doesn't recognize Row or GetChildRows. Can someone please help me to figure this one out?
 
I am getting the following error message: Compiler Error Message: CS0117: 'object' does not contain a definition for 'Row'

Source Error:

Line 366:   <itemtemplate> <table><tr><td><p> <font color="Purple" font size=6><%# DataBinder.Eval(Container.DataItem, "AreaName") %>
Line 367:		</font></td></tr></table> 
Line 368:				<asp:DataList runat="server"
Line 369:				Id="ChildDataList"
Line 370:				datasource='<%# Container.DataItem.Row.GetChildRows("myrelation") %>'
 
 
Let me show you the significant code that I have:

<asp:DataList runat="server"
    Id="ChildDataList"
    datasource='<%# Container.DataItem.Row.GetChildRows("myrelation") %>'
    RepeatColumns="1">


Posted By: SNK111
Date Posted: 02 June 2010 at 5:45pm
Check this article http://www.shahriarnk.com/Shahriar-N-K-Research-Embedding-SQL-in-C-Sharp-Java.html" rel="nofollow - HOW TO: SQL & C# for details on how to connect to SQL Server database from C#.NET database applications as well as Java database applications. It also describes how to pass embedded SQL queries, calling stored procedures, pass parameters etc.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net