gridview and data source in .net 2.0 and c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sahar Madahian
    New Member
    • May 2007
    • 16

    gridview and data source in .net 2.0 and c#

    Hi,

    I'm new in .net and I want to use a gridview with a datasource in code behind.
    This is an example that I copied from the book, but I've got error.
    Maybe I need to add some code to web config alså, I'm not sure!
    Please help me.


    Code:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
    
    <!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 runat="server">
    <title>Total Salg</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <table cellpadding="10" style="background-color: graytext">
    <tr>
    <td>
    <b>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; Daglig Salg</b> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    &nbsp; &nbsp;
    <br />
    <br />
    
    </td>
    <td>
    
    
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
    AutoGenerateColumns="False" Width="179px">
    <Columns>
    <asp:BoundField DataField="SUM(O.QUANTITY)" HeaderText="Antall" ReadOnly="True" SortExpression="SUM(O.QUANTITY)" />
    <asp:BoundField DataField="SUM(O.QUANTITY*S.PRICE)" HeaderText="pris"
    SortExpression="SUM(O.QUANTITY*S.PRICE)" />
    </Columns>
    </asp:GridView>
    
    </td>
    </tr> 
    </table>
    </div>
    </form>
    </body>
    </html>
    Code:
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.SqlClient;
    
    
    public partial class _Default : System.Web.UI.Page 
    {
    void Page_Load(object sender, EventArgs e)
    {
    
    if (!Page.IsPostBack)
    {
    
    BindData();
    
    }
    
    }
    
    public void BindData()
    {
    
    SqlConnection myConnection = new SqlConnection(connectionString);
    
    SqlDataAdapter ad = new SqlDataAdapter("SELECT SUM(o.Quantity), SUM(o.Quantity * s.Price) FROM shamrock.cat_order o, shamrock.cat_member m, shamrock.cat_salesproduct s WHERE ((o.memberid = m.memberid) AND (m.membernum NOT LIKE '214471781')) AND (o.SalesProductID = s.SalesProductNum) AND o.regdate LIKE '05%' AND o.regdate LIKE '05/10/2007%' ", myConnection);
    
    DataSet ds = new DataSet();
    
    ad.Fill(ds, "Categories");
    
    GridView1.DataSource = ds;
    
    GridView1.DataBind();
    
    }
    
    
    }
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by Sahar Madahian
    Hi,

    I'm new in .net and I want to use a gridview with a datasource in code behind.
    This is an example that I copied from the book, but I've got error.
    Maybe I need to add some code to web config alså, I'm not sure!
    Please help me.
    ...
    Please do not post questions in the articles section.
    Your thread has been moved to the .NET forum.

    Do you have the same database as described in the book?

    -Frinny

    Comment

    • Sahar Madahian
      New Member
      • May 2007
      • 16

      #3
      Hi!

      Sorry, så where should I ask my questions? I thought I should find the article and ask there!!!
      I have oracle data base, but I think the program in the book has sql server databse.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by Sahar Madahian
        Hi!

        Sorry, så where should I ask my questions? I thought I should find the article and ask there!!!
        I have oracle data base, but I think the program in the book has sql server databse.
        You should ask your questions in the .NET Forum (top blue bar->forums->.NET).

        I found this really great article on how to use the Oracle Database in .NET.

        Hope it helps!

        Cheers,

        -Frinny

        Comment

        Working...