List Info

Thread: C-Sharp (C#) Group: Calling a stored procedure




C-Sharp (C#) Group: Calling a stored procedure
country flaguser name
United States
2007-02-21 02:24:33
Hi,

I'm a student and have the following working example on an
aspx page
(.NET 2.00) (C# code Page_Load):

try
        {
            if (User.Identity.IsAuthenticated == true)
            {
                try
                {
                    string theUser;
                    theUser = User.Identity.Name;
                    this.lblUsername.Text = theUser;
                    SqlConnection conn = new
SqlConnection(GetConnectionString());
                    SqlCommand cmd = new
SqlCommand("dbo.CustomersOrderHistory", conn);
                    cmd.CommandType =
CommandType.StoredProcedure;
                    cmd.Parameters.Add("Firstname",
SqlDbType.VarChar).Value = theUser;
                    conn.Open();
                    SqlDataReader rd = cmd.ExecuteReader();
                    while (rd.Read())
                    {
                        gvCustOrdHist.DataBind();
                    }
                    conn.Close();
                }
                catch (SqlException sqlex)
                {
                    lblError.Text = "An database error
occurred with
text: " + "n" + "n" +
                        sqlex.Message;
                }
            }
}

Now the stored procedure is(SQL Server 2005):

CREATE PROCEDURE dbo.CustomersOrderHistory
( Firstname varchar(7))
AS
SELECT     dbo.Customers.Firstname, dbo.Orders.Orderdate,
dbo.Orderdetails.Orderamount, dbo.Orderdetails.Orderprice,
dbo.Orderdetails.Orderdiscount,
                     
dbo.Items.Itemname,dbo.Orderdetails.Orderamount
* dbo.Orderdetails.Orderprice AS Ordersum
FROM         dbo.Orderdetails INNER JOIN
                      dbo.Items ON dbo.Orderdetails.ItemID
=
dbo.Items.ItemID INNER JOIN
                      dbo.Orders ON dbo.Orderdetails.OrderID
=
dbo.Orders.OrderID INNER JOIN
                      dbo.Customers ON dbo.Orders.Customer
=
dbo.Customers.CustomerID
                      WHERE dbo.Customers.Firstname LIKE
Firstname
                      ORDER BY dbo.Orders.Orderdate
	/* SET NOCOUNT ON */
	RETURN ERROR

However, no data is returned and I wonder why. Can you see
why?

The connection string:

private static string GetConnectionString()
    {
        return
ConfigurationManager.ConnectionStrings["csCustomersOrde
rHistory"].ConnectionString;
    }

It works ok if I use a dataset, but I want to use
DataReader.

Any tip?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://g
roups.google.com/group/C_Sharp?hl=en
-~----------~----~----~----~------~----~------~--~---


C-Sharp (C#) Group: Re: Calling a stored procedure
user name
2007-02-21 02:41:10
here is no comma separator

dbo.Orderdetails.Orderamount
*
dbo.Orderdetails.Orderprice AS Ordersum
FROM    dbo.Orderdetails

it should be :

dbo.Orderdetails.Orderamount,
*,
dbo.Orderdetails.Orderprice AS Ordersum
FROM    dbo.Orderdetails

On 2/21/07, Krij < gsb58start.no">gsb58start.no&gt; wrote:

Hi,

I&#39;m a student and have the following working example on an aspx page
(.NET 2.00) (C# code Page_Load):

try
&nbsp; &nbsp; &nbsp; &nbsp; {
 &nbsp; &nbsp; &nbsp;   ; &nbsp; if (User.Identity.IsAuthenticated == true)
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp;{
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;try
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;{
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;string theUser;
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; theUser = User.Identity.Name;
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; this.lblUsername.Text = theUser;
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; SqlConnection conn = new
SqlConnection(GetConnectionString());
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; SqlCommand cmd = new
SqlCommand("dbo.CustomersOrderHistory", conn);
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;  cmd.CommandType = CommandType.StoredProcedure;
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; cmd.Parameters.Add("Firstname&quot;,
SqlDbType.VarChar).Value = theUser;
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; conn.Open();
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; SqlDataReader rd = cmd.ExecuteReader();
 &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;while (rd.Read())
 &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;{
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;gvCustOrdHist.DataBind();
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; }
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; conn.Close();
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; }
 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; catch (SqlException sqlex)
&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  lblError.Text = "An database error occurred with
text: " + "n&quot; + "n&quot; +
 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; sqlex.Message;
&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; }
&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;}
}

Now the stored procedure is(SQL Server 2005):

CREATE PROCEDURE dbo.CustomersOrderHistory
( Firstname varchar(7))
AS
SELECT  ; &nbsp; dbo.Customers.Firstname , dbo.Orders.Orderdate,
dbo.Orderdetails.Orderamount, dbo.Orderdetails.Orderprice,
dbo.Orderdetails.Orderdiscount,
&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; dbo.Items.Itemname,dbo.Orderdetails.Orderamount
* dbo.Orderdetails.Orderprice AS Ordersum
FROM &nbsp; &nbsp;   ;  dbo.Orderdetails INNER JOIN
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  dbo.Items ON dbo.Orderdetails.ItemID =
dbo.Items.ItemID INNER JOIN
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  dbo.Orders ON dbo.Orderdetails.OrderID =
dbo.Orders.OrderID INNER JOIN
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  dbo.Customers ON dbo.Orders.Customer =
dbo.Customers.CustomerID
 ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;  WHERE dbo.Customers.Firstname LIKE Firstname
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; ORDER BY dbo.Orders.Orderdate
 &nbsp; &nbsp; &nbsp;  /* SET NOCOUNT ON */
 &nbsp;   ; &nbsp; RETURN ERROR

However, no data is returned and I wonder why. Can you see why?

The connection string:

private static string GetConnectionString()
 &nbsp; &nbsp;{
&nbsp; &nbsp; &nbsp; &nbsp; return
ConfigurationManager.ConnectionStrings["csCustomersOrderHistory&quot;].ConnectionString;
 &nbsp; &nbsp;}

It works ok if I use a dataset, but I want to use DataReader.

Any tip?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/C_Sharp?hl=en
-~----------~----~----~----~------~----~------~--~---

C-Sharp (C#) Group: Re: Calling a stored procedure
country flaguser name
United States
2007-02-21 03:22:40
Sorry, you are wrong my friend 

There is no need to separate an aggregated field with comma.
It would
become two fields which is not the intention. Or...?

dbo.Orderdetails.Orderamount * dbo.Orderdetails.Orderprice
AS
Ordersum

On 21 Feb, 09:41, "ivan ivan" <verth...gmail.com> wrote:
> here is no comma separator 
>
> dbo.Orderdetails.Orderamount
> *
> dbo.Orderdetails.Orderprice AS Ordersum
> FROM    dbo.Orderdetails
>
> it should be :
>
> dbo.Orderdetails.Orderamount,
> *,
> dbo.Orderdetails.Orderprice AS Ordersum
> FROM    dbo.Orderdetails
>
> On 2/21/07, Krij <g...start.no> wrote:
>
>
>
> > Hi,
>
> > I'm a student and have the following working
example on an aspx page
> > (.NET 2.00) (C# code Page_Load):
>
> > try
> >         {
> >             if (User.Identity.IsAuthenticated ==
true)
> >             {
> >                 try
> >                 {
> >                     string theUser;
> >                     theUser = User.Identity.Name;
> >                     this.lblUsername.Text =
theUser;
> >                     SqlConnection conn = new
> > SqlConnection(GetConnectionString());
> >                     SqlCommand cmd = new
> > SqlCommand("dbo.CustomersOrderHistory",
conn);
> >                     cmd.CommandType =
CommandType.StoredProcedure;
> >                     cmd.Parameters.Add("Firstname",
> > SqlDbType.VarChar).Value = theUser;
> >                     conn.Open();
> >                     SqlDataReader rd =
cmd.ExecuteReader();
> >                     while (rd.Read())
> >                     {
> >                         gvCustOrdHist.DataBind();
> >                     }
> >                     conn.Close();
> >                 }
> >                 catch (SqlException sqlex)
> >                 {
> >                     lblError.Text = "An
database error occurred with
> > text: " + "n" + "n" +
> >                         sqlex.Message;
> >                 }
> >             }
> > }
>
> > Now the stored procedure is(SQL Server 2005):
>
> > CREATE PROCEDURE dbo.CustomersOrderHistory
> > ( Firstname varchar(7))
> > AS
> > SELECT     dbo.Customers.Firstname,
dbo.Orders.Orderdate,
> > dbo.Orderdetails.Orderamount,
dbo.Orderdetails.Orderprice,
> > dbo.Orderdetails.Orderdiscount,
> >                      
dbo.Items.Itemname,dbo.Orderdetails.Orderamount
> > * dbo.Orderdetails.Orderprice AS Ordersum
> > FROM         dbo.Orderdetails INNER JOIN
> >                       dbo.Items ON
dbo.Orderdetails.ItemID =
> > dbo.Items.ItemID INNER JOIN
> >                       dbo.Orders ON
dbo.Orderdetails.OrderID =
> > dbo.Orders.OrderID INNER JOIN
> >                       dbo.Customers ON
dbo.Orders.Customer =
> > dbo.Customers.CustomerID
> >                       WHERE
dbo.Customers.Firstname LIKE Firstname
> >                       ORDER BY
dbo.Orders.Orderdate
> >         /* SET NOCOUNT ON */
> >         RETURN ERROR
>
> > However, no data is returned and I wonder why. Can
you see why?
>
> > The connection string:
>
> > private static string GetConnectionString()
> >     {
> >         return
> > ConfigurationManager.ConnectionStrings
> >
["csCustomersOrderHistory"].ConnectionString;
> >     }
>
> > It works ok if I use a dataset, but I want to use
DataReader.
>
> > Any tip?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharpgooglegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribegooglegroups.com
For more options, visit this group at http://g
roups.google.com/group/C_Sharp?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )