Showing posts with label aspx. Show all posts
Showing posts with label aspx. Show all posts

Monday, March 26, 2012

return @@rowcount from stored proc

Hi

I'm using an sqldatasource control in my aspx page, and then executing it from my code behind page (SqlDataSource1.Insert()), how do i retrieve the number of rows (@.@.rowcount) which have been inserted into the database and display it in my aspx page. I am using a stored procedure.

thanks

Hello Mattock,

Have a look at the following article about using stored procedure to update data:http://msdn2.microsoft.com/en-us/library/59x02y99(VS.80).aspx

Jeroen Molenaar.

sql

Monday, March 12, 2012

retrieving data as xml from sql server

I am trying to retrieve SQL data from multiple tables (SQl Server 2000) and present it in XML in the browser (result.aspx page). I am using "for xml explicit" to retrieve the data. But I am having trouble in displaying the data since I would have to valid
ate the xml against the dtd.
could anyone tell me how to validate the XML document and present it in the browser after I have retrieved the data ?
thanks!
- garfieldinstore
the dtd is as follows:
<!ELEMENT WebOrders(WebOrder*)>
<!ATTLIST WebOrders
NumberOfOrders CDATA #REQUIRED
>
<!ELEMENTWebOrder(Order, WebComment)>
<!ELEMENTWebComment (#CDATA)>
<!ELEMENT Order (
AddressInfo*,
Shipping?,
CreditCard?,
Comments?,
Item*,
Total,
)>
<!ATTLIST Order
id CDATA #REQUIRED
currency CDATA #REQUIRED
>
<!ELEMENT AddressInfo (Name,
Address1?,
Address2?,
City?,
State?,
Country?,
Zip?,
Phone?,
Email?,
Custom*
)>
<!ATTLIST AddressInfo
type (ship|bill) #REQUIRED
>
<!ELEMENT Name (First,
Last,
Full
)>
<!ELEMENT First (#PCDATA)>
<!ELEMENT Last (#PCDATA)>
<!ELEMENT Full (#PCDATA)>
<!ELEMENT Address1 (#PCDATA)>
<!ELEMENT Address2 (#PCDATA)>
<!ELEMENT City (#PCDATA)>
<!ELEMENT State (#PCDATA)>
<!ELEMENT Country (#PCDATA)>
<!ELEMENT Zip (#PCDATA)>
<!ELEMENT Phone (#PCDATA)>
<!ELEMENT Email (#PCDATA)>
<!ELEMENT Custom (#PCDATA)>
<!ATTLIST Custom
name CDATA #REQUIRED
>
<!ELEMENT Shipping (#PCDATA)>
<!ELEMENT CreditCard (#PCDATA)>
<!ATTLIST CreditCard
type CDATA #REQUIRED
expiration CDATA #REQUIRED
>
<!ELEMENT Comments (#PCDATA)>
<!ELEMENT Item (
Code,
Quantity,
Unit-Price,
Description,
Option*,
)>
<!ATTLIST Item
num CDATA #IMPLIED
>
<!ELEMENT Code (#PCDATA)>
<!ELEMENT Quantity (#PCDATA)>
<!ELEMENT Unit-Price (#PCDATA)>
<!ELEMENT Description (#PCDATA)>
<!ELEMENT Option (#PCDATA)>
<!ATTLIST Option
name CDATA #REQUIRED
>
<!--
In an effort to programmatically access the Line items, we provide a canonical type attribute which will be one of the enumerated values listed below.
-->
<!ELEMENT Total (Line*)>
<!ELEMENT Line (#PCDATA)>
<!ATTLIST Line
type (GiftWrap|Discount|MiscAdjustment|
Coupon|GiftCertificate|Subtotal|
Shipping|Tax|Credit|Total) #IMPLIED
name CDATA #REQUIRED
notes CDATA #IMPLIED
>
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
You could read the XML into an XmlValidatingReader object and use that to
validate it before rendering it. See
http://msdn.microsoft.com/library/de...tingReader.asp
for more info.
Alternatively, you could use an XML schema instead of a DTD and add
annotations to the schema to map it to the data - SQLXML would then
automatically generate the appropriate FOR XML EXPLICIT query at runtime.
See
http://msdn.microsoft.com/library/de...tions_0gqb.asp
for more info.
Hope that helps,
Graeme
--
Graeme Malcolm
Principal Technologist
Content Master Ltd.
www.contentmaster.com
www.microsoft.com/mspress/books/6137.asp
"SqlJunkies User" <User@.-NOSPAM-SqlJunkies.com> wrote in message
news:OB2NPFuNEHA.2468@.TK2MSFTNGP11.phx.gbl...
> I am trying to retrieve SQL data from multiple tables (SQl Server 2000)
and present it in XML in the browser (result.aspx page). I am using "for xml
explicit" to retrieve the data. But I am having trouble in displaying the
data since I would have to validate the xml against the dtd.
> could anyone tell me how to validate the XML document and present it in
the browser after I have retrieved the data ?
> thanks!
> - garfieldinstore
> the dtd is as follows:
> <!ELEMENT WebOrders(WebOrder*)>
> <!ATTLIST WebOrders
> NumberOfOrders CDATA #REQUIRED
> <!ELEMENT WebOrder(Order, WebComment)>
> <!ELEMENT WebComment (#CDATA)>
> <!ELEMENT Order (
> AddressInfo*,
> Shipping?,
> CreditCard?,
> Comments?,
> Item*,
> Total,
> )>
> <!ATTLIST Order
> id CDATA #REQUIRED
> currency CDATA #REQUIRED
> <!ELEMENT AddressInfo (Name,
> Address1?,
> Address2?,
> City?,
> State?,
> Country?,
> Zip?,
> Phone?,
> Email?,
> Custom*
> )>
> <!ATTLIST AddressInfo
> type (ship|bill) #REQUIRED
> <!ELEMENT Name (First,
> Last,
> Full
> )>
> <!ELEMENT First (#PCDATA)>
> <!ELEMENT Last (#PCDATA)>
> <!ELEMENT Full (#PCDATA)>
> <!ELEMENT Address1 (#PCDATA)>
> <!ELEMENT Address2 (#PCDATA)>
> <!ELEMENT City (#PCDATA)>
> <!ELEMENT State (#PCDATA)>
> <!ELEMENT Country (#PCDATA)>
> <!ELEMENT Zip (#PCDATA)>
> <!ELEMENT Phone (#PCDATA)>
> <!ELEMENT Email (#PCDATA)>
> <!ELEMENT Custom (#PCDATA)>
> <!ATTLIST Custom
> name CDATA #REQUIRED
> <!ELEMENT Shipping (#PCDATA)>
> <!ELEMENT CreditCard (#PCDATA)>
> <!ATTLIST CreditCard
> type CDATA #REQUIRED
> expiration CDATA #REQUIRED
> <!ELEMENT Comments (#PCDATA)>
> <!ELEMENT Item (
> Code,
> Quantity,
> Unit-Price,
> Description,
> Option*,
> )>
> <!ATTLIST Item
> num CDATA #IMPLIED
> <!ELEMENT Code (#PCDATA)>
> <!ELEMENT Quantity (#PCDATA)>
> <!ELEMENT Unit-Price (#PCDATA)>
> <!ELEMENT Description (#PCDATA)>
> <!ELEMENT Option (#PCDATA)>
> <!ATTLIST Option
> name CDATA #REQUIRED
> <!--
> In an effort to programmatically access the Line items, we provide a
canonical type attribute which will be one of the enumerated values listed
below.
> -->
> <!ELEMENT Total (Line*)>
> <!ELEMENT Line (#PCDATA)>
> <!ATTLIST Line
> type (GiftWrap|Discount|MiscAdjustment|
> Coupon|GiftCertificate|Subtotal|
> Shipping|Tax|Credit|Total) #IMPLIED
> name CDATA #REQUIRED
> notes CDATA #IMPLIED
>
>
> --
> Posted using Wimdows.net NntpNews Component -
> Post Made from http://www.SqlJunkies.com/newsgroups Our newsgroup engine
supports Post Alerts, Ratings, and Searching.

Friday, March 9, 2012

Retrieving an Image from SQL Server

Hello and thanks for taking a moment. I am trying to retrieve and display an image that is stored in SQL Server 2000. My aspx code is as follows:

<HTML>
<HEAD>
<title>photoitem</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid3" HorizontalAlign='Left' runat="server" AutoGenerateColumns="true"
Visible="True">
<Columns>
<asp:TemplateColumn HeaderText="Image">
<ItemTemplate>
<asp:Image
Width="150" Height="125"
ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "InventoryItemPhoto")) %>'
Runat=server />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>

-----------------------------------------------------------------------------------My code behind file is below VS 2003 does not like my datareader. It says the following:

'System.Data.SqlClient.SqlDataReader' does not contain a definition for 'Items'

If there are any suggestions as to what I am doing wrong I would appreciate the input. - Jason

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;

namespace ActionLinkAdHoc
{
/// <summary>
/// Summary description for photoitem.
/// </summary>
public class photoitem : System.Web.UI.Page
{
string connStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
protected System.Web.UI.WebControls.DataGrid DataGrid3;
private void Page_Load(object sender, System.EventArgs e)
{
// Get the querystring ID
string item =Request.QueryString["ID"];
int ID=Convert.ToInt32(item);

SqlConnection dbConn5 = new SqlConnection(connStr);
SqlCommand sqlCom5 =new SqlCommand("sp4TWRetrieveItemPhotos");
sqlCom5.Connection = dbConn5;
sqlCom5.CommandType = CommandType.StoredProcedure;
sqlCom5.Parameters.Add("@.ID", SqlDbType.Int);
sqlCom5.Parameters["@.ID"].Value =ID;
dbConn5.Open();
SqlDataReader myDataReader;
myDataReader = sqlCom5.ExecuteReader(CommandBehavior.CloseConnection);
DataGrid3.DataSource = sqlCom5.ExecuteReader();
DataGrid3.DataBind();
while(myDataReader.Read())
{
Response.ContentType = myDataReader.Items("JPEG");
Response.BinaryWrite(myDataReader.Items("InventoryItemPhoto"));
}
dbConn5.Close();

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

The problem is with your code here:

myDataReader.Items("JPEG")

The .Items property is VB syntax. You need to use C# syntax - myDataReader("JPEG")

That should clear up your compile problem.

Retrieving an Image from SQL Server

Hello and thanks for taking a moment. I am trying to retrieve and display an image that is stored in SQL Server 2000. My aspx code is as follows:

<HTML>
<HEAD>
<title>photoitem</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid3" HorizontalAlign='Left' runat="server" AutoGenerateColumns="true"
Visible="True">
<Columns>
<asp:TemplateColumn HeaderText="Image">
<ItemTemplate>
<asp:Image
Width="150" Height="125"
ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "InventoryItemPhoto")) %>'
Runat=server />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>

-----------------------------------------------------------------------------------My code behind file is below VS 2003 does not like my datareader. It says the following:

'System.Data.SqlClient.SqlDataReader' does not contain a definition for 'Items'

If there are any suggestions as to what I am doing wrong I would appreciate the input. - Jason

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Text;

namespace ActionLinkAdHoc
{
/// <summary>
/// Summary description for photoitem.
/// </summary>
public class photoitem : System.Web.UI.Page
{
string connStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
protected System.Web.UI.WebControls.DataGrid DataGrid3;
private void Page_Load(object sender, System.EventArgs e)
{
// Get the querystring ID
string item =Request.QueryString["ID"];
int ID=Convert.ToInt32(item);

SqlConnection dbConn5 = new SqlConnection(connStr);
SqlCommand sqlCom5 =new SqlCommand("sp4TWRetrieveItemPhotos");
sqlCom5.Connection = dbConn5;
sqlCom5.CommandType = CommandType.StoredProcedure;
sqlCom5.Parameters.Add("@.ID", SqlDbType.Int);
sqlCom5.Parameters["@.ID"].Value =ID;
dbConn5.Open();
SqlDataReader myDataReader;
myDataReader = sqlCom5.ExecuteReader(CommandBehavior.CloseConnection);
DataGrid3.DataSource = sqlCom5.ExecuteReader();
DataGrid3.DataBind();
while(myDataReader.Read())
{
Response.ContentType = myDataReader.Items("JPEG");
Response.BinaryWrite(myDataReader.Items("InventoryItemPhoto"));
}
dbConn5.Close();

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
}
}

This seems to be a duplicate post, let's focus on the other oneSmile