Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Problem with C# Code
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Problem with C# Code

 Post Reply Post Reply
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Problem with C# Code
    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();
 
 
 
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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;

Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post 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;
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 19 January 2005 at 2:33pm
You need

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

Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post 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!

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 19 January 2005 at 3:02pm
Try this:

<%# DataBinder.Eval(Container, "DataItem.AreaName") %>
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post 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">
Back to Top
SNK111 View Drop Down
Newbie
Newbie


Joined: 02 June 2010
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote SNK111 Quote  Post ReplyReply Direct Link To This Post Posted: 02 June 2010 at 5:45pm
Check this article 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.

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.