| Author |
Topic Search Topic Options
|
Misty
Senior Member
Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
|
Post Options
Thanks(0)
Quote Reply
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();
|
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
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;
|
 |
Misty
Senior Member
Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
|
Post Options
Thanks(0)
Quote Reply
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;
|
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 19 January 2005 at 2:33pm |
You need
dlArea.DataSource = ds.Tables["Area"].DefaultView;
|
 |
Misty
Senior Member
Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
|
Post Options
Thanks(0)
Quote Reply
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!
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 19 January 2005 at 3:02pm |
|
Try this:
<%# DataBinder.Eval(Container, "DataItem.AreaName") %>
|
 |
Misty
Senior Member
Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
|
Post Options
Thanks(0)
Quote Reply
Posted: 20 January 2005 at 1:05am |
I have another problem in C#. It worked fine in VB.Net.  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">
|
|
 |
SNK111
Newbie
Joined: 02 June 2010
Status: Offline
Points: 2
|
Post Options
Thanks(0)
Quote Reply
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.
|
 |