Showing posts with label back. Show all posts
Showing posts with label back. Show all posts

Saturday, March 31, 2012

Senility Setting In?

I've been working on some differnt projects for a while and I just got back to an ASP.NET 2.0 (VB) project and I seem to have forgotten (screwed up?) some basics. I created a new form (using a master page) and I simply want to read and use an integer value from a SQL Table (see code below). In this code, "conn" gets flagged as "Declaration expected" in the Open and Close statements (but it is OK in the Dim cmd1... statement?). I want to retrieve the residentid integer value from the table and pass it as a query parameter in the link to residentfeature.aspx - I can't find the correct syntax to accomplish that either.

I know I must be missing something very basic here but I can't see it?

================ Code ================

<%

@dotnet.itags.org.ImportNamespace="System.Data" %>

<%

@dotnet.itags.org.ImportNamespace="System.Data.SQLClient" %>

<%@dotnet.itags.org. Page Language="VB" MasterPageFile="~/Default.master" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
Dim residentid As Integer
<script runat="server">
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("GoodSamSiteDB").ConnectionString)
Dim cmd1 As New SqlCommand("SELECT resident From Features", conn)
conn.Open()
residentid = cmd1.ExecuteScalar()
conn.Close()
</script>
<div id="body">
<div class="fullwidth">
<h2>Weekly Features</h2>
<h3>Featured Resident</h3>
<a href="http://links.10026.com/?link=residentfeature.aspx?id=" + residentid + >Meet Mary Jones</a>
</div>
</div>
</asp:Content>

I am no VB expert (hence the vcs in my name) but I think this will remedy the problem:
Dim connAs SqlConnection =New SqlConnection(ConfigurationManager.ConnectionStrings("GoodSamSiteDB").ConnectionString)Dim cmd1As SqlCommand =New SqlCommand("SELECT resident From Features", conn)

Also, ExecuteScalar returns object, so to assign it as an Integer, you would need to cast it or use Int32.Parse() or Int32.TryParse()

Kevin;

Thanks for the response but that change had no effect?


try this
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script runat="server">
Dim residentid As Integer
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("GoodSamSiteDB").ConnectionString)
Dim cmd1 As New SqlCommand("SELECT resident From Features", conn)
conn.Open()
residentid = cmd1.ExecuteScalar()
conn.Close()
End Sub
</script>
<a href="http://links.10026.com/?link=residentfeature.aspx?id=<%= residentid %>">Meet Mary Jones</a>
or
<asp:HyperLink id=HyperLink1 Text="Meet Mary Jones" NavigateUrl='<%# "detailspage_vb.aspx?id=" + residentid%>' runat="server"/>
you needed to wrap the code in an event

Thursday, March 29, 2012

Separate VB app to talk back to a Web Service

Customer sends XML data to our Web Service. Web Service does some
data transformation and puts the data into a special format that
another application uses. That data is in a file.
This other application continuously polls a folder for these data
files and processes them. It eventually creates a PDF out of the
data with a unique file name.
Web service needs to know when this other application is done
processing this data so I can send a URL of the created PDF back to
customer.
What would be the best way to do this? I don't want to sit there and
poll a folder for the output file, as we may have up to 40,000
requests / day.look at windows workflow or sqlserver broker services.
-- bruce (sqlwork.com)
"Larry Bud" wrote:

> Customer sends XML data to our Web Service. Web Service does some
> data transformation and puts the data into a special format that
> another application uses. That data is in a file.
> This other application continuously polls a folder for these data
> files and processes them. It eventually creates a PDF out of the
> data with a unique file name.
> Web service needs to know when this other application is done
> processing this data so I can send a URL of the created PDF back to
> customer.
> What would be the best way to do this? I don't want to sit there and
> poll a folder for the output file, as we may have up to 40,000
> requests / day.
>
In addition to Bruce's suggestion - what I have done in the past is have a
method that allows the client to check a DB value against each created file
using the number they are given on submission. For me it was word files
converted to PDF and a succesful creation triggered a DB update and then
stored the output URL - cleaning up after a 24 hour period. Because its
only a small request with a single return value it was cheap for the client
to check the webservice for a success flag and then get the URL. This
didn't massively impact throughput and could be hosted on a different app
server entirely.
Regards
John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"bruce barker" <brucebarker@.discussions.microsoft.com> wrote in message
news:7BFFAD45-86AA-48B5-AFB1-42DB21056491@.microsoft.com...
> look at windows workflow or sqlserver broker services.
> -- bruce (sqlwork.com)
>
> "Larry Bud" wrote:
>
On Feb 11, 4:37=A0pm, "John Timney \(MVP\)"
<xyz_j...@.timney.eclipse.co.uk> wrote:
> In addition to Bruce's suggestion - what I have done in the past is have a=[/color
]
> method that allows the client to check a DB value against each created fil=[/color
]
e
> using the number they are given on submission. =A0For me it was word files=[/color
]
> converted to PDF and a succesful creation triggered a DB update and then
> stored the output URL - cleaning up after a 24 hour period. =A0Because its=[/color
]
> only a small request with a single return value it was cheap for the clien=[/color
]
t
> to check the webservice for a success flag and then get the URL. =A0This
> didn't massively impact throughput and could be hosted on a different app
> server entirely.
>
Wouldn't you have to keep hitting the database to see if the file was
created successfully?
Yes, but it doesn't have to be the same database, or even the same database
server!
Regards
John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
"Larry Bud" <larrybud2002@.yahoo.com> wrote in message
news:e2449b23-38af-4876-88c5-df0f10f77278@.s8g2000prg.googlegroups.com...
On Feb 11, 4:37 pm, "John Timney \(MVP\)"
<xyz_j...@.timney.eclipse.co.uk> wrote:
> In addition to Bruce's suggestion - what I have done in the past is have a
> method that allows the client to check a DB value against each created
> file
> using the number they are given on submission. For me it was word files
> converted to PDF and a succesful creation triggered a DB update and then
> stored the output URL - cleaning up after a 24 hour period. Because its
> only a small request with a single return value it was cheap for the
> client
> to check the webservice for a success flag and then get the URL. This
> didn't massively impact throughput and could be hosted on a different app
> server entirely.
>
Wouldn't you have to keep hitting the database to see if the file was
created successfully?

Seperating code from HTML markup

Hello All:
I am writing to ask for your opinions. I have a colleague who combines his
code with the markup used to display the code (reckoning back to classic
ASP). Here's an example of a datagrid column:
<asp:TemplateColumn>
<ItemStyle CssClass="TableData" Width="15%"></ItemStyle>
<ItemTemplate>
<a href="http://links.10026.com/?link=<%# ShowURL(DataBinder.Eval(Container.DataItem,
"FORM_ID"))%>" target="_blank">
<%# DataBinder.Eval(Container.DataItem, "FORM_NUMBER")%></a>
</ItemTemplate>
</asp:TemplateColumn>
or another column
<asp:TemplateColumn>
<ItemStyle CssClass="TableData" Width="20%"></ItemStyle>
<ItemTemplate>
<%# DisplayState(DataBinder.EvalContainer.DataItem,
"FORM_STATE_CD"))%>
</ItemTemplate>
</asp:TemplateColumn>
Where ShowURL and DisplayState are defined in the code-behind. We have the
restriction that we can not use ViewState when creating our webforms
(security breach due to how they have architected their web app). I wonder
if there is a bettre way to do this.
In my opinion, this is sloppy programming. I, however, could be wrong.
Maybe this is the best way to do this. So I am asking:
What is your opinion regarding mixiing content and functionality.
If you think that this could have been done differnetly, What would you have
done? Is there a better way to do this?
Finally, the IDE will not display the Design View of the page that contains
this markup. The message says "Could not open in Design View. Quote values
differently inside of a '<% ...value... %>' block."
Thank you for your input.
--
JoeAs for the designer error, simply switching:
a href="http://links.10026.com/?link=<%# ShowURL(DataBinder.Eval(Container.DataItem, "FORM_ID"))%>"
target="_blank">
to:
a href='<%# ShowURL(DataBinder.Eval(Container.DataItem, "FORM_ID"))%>'
target="_blank">
should solve that (replace the " around the <%# ... %> with ' )
As far as I'm concerned, the question is pretty trivial. The separation of
code and HTML is almost complete in your examples below. ShowURL and
DisplayState both represent functionality that resides outside the HTML, and
if it needs to be reused, it could easily be extracted to a seperate code
file. The only way to achieve even greater separation is to hook into the
OnItemDataBound event and write a considerable chunk of code. For any
complex binding, this will result in a lot of code generating HTML. I've
seen code that took this approach, and it's an absolute nightmare. You end
with huge amounts of html created in code (new Table(), new TableRow(),
table.Rows.Add(tr), new TableCell(), new Label(), label.Text = SomeDBValue;
cell.Controls.Add(label), row.Cells.Add(cell)...), which is far harder to
maintain and change than the examples below.
The code has pretty good abstraction
1 - it uses methods located in codebehind for any actual processing
2 - It uses DataBinder.Eval which abstracts away the business layer
implementation (is Container.DataItem a datarowview ora custom class? who
knows, and why should the presentation layer care?)
I think you'll find that the benefits of further separation aren't worth
the high price you'll end up paying
Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:65EF2A6E-0440-4DFC-B8B5-AE49C4C8BBA1@.microsoft.com...
> Hello All:
> I am writing to ask for your opinions. I have a colleague who combines
> his
> code with the markup used to display the code (reckoning back to classic
> ASP). Here's an example of a datagrid column:
> <asp:TemplateColumn>
> <ItemStyle CssClass="TableData" Width="15%"></ItemStyle>
> <ItemTemplate>
> <a href="http://links.10026.com/?link=<%# ShowURL(DataBinder.Eval(Container.DataItem,
> "FORM_ID"))%>" target="_blank">
> <%# DataBinder.Eval(Container.DataItem, "FORM_NUMBER")%></a>
> </ItemTemplate>
> </asp:TemplateColumn>
> or another column
> <asp:TemplateColumn>
> <ItemStyle CssClass="TableData" Width="20%"></ItemStyle>
> <ItemTemplate>
> <%# DisplayState(DataBinder.EvalContainer.DataItem,
> "FORM_STATE_CD"))%>
> </ItemTemplate>
> </asp:TemplateColumn>
> Where ShowURL and DisplayState are defined in the code-behind. We have
> the
> restriction that we can not use ViewState when creating our webforms
> (security breach due to how they have architected their web app). I
> wonder
> if there is a bettre way to do this.
> In my opinion, this is sloppy programming. I, however, could be wrong.
> Maybe this is the best way to do this. So I am asking:
> What is your opinion regarding mixiing content and functionality.
> If you think that this could have been done differnetly, What would you
> have
> done? Is there a better way to do this?
> Finally, the IDE will not display the Design View of the page that
> contains
> this markup. The message says "Could not open in Design View. Quote
> values
> differently inside of a '<% ...value... %>' block."
> Thank you for your input.
> --
> Joe
Thank you Karl. This helped. As always, I appreciate your input.
--
Joe
"Karl Seguin [MVP]" wrote:

> As for the designer error, simply switching:
> a href="http://links.10026.com/?link=<%# ShowURL(DataBinder.Eval(Container.DataItem, "FORM_ID"))%>"
> target="_blank">
> to:
> a href='<%# ShowURL(DataBinder.Eval(Container.DataItem, "FORM_ID"))%>'
> target="_blank">
> should solve that (replace the " around the <%# ... %> with ' )
> As far as I'm concerned, the question is pretty trivial. The separation of
> code and HTML is almost complete in your examples below. ShowURL and
> DisplayState both represent functionality that resides outside the HTML, a
nd
> if it needs to be reused, it could easily be extracted to a seperate code
> file. The only way to achieve even greater separation is to hook into the
> OnItemDataBound event and write a considerable chunk of code. For any
> complex binding, this will result in a lot of code generating HTML. I've
> seen code that took this approach, and it's an absolute nightmare. You en
d
> with huge amounts of html created in code (new Table(), new TableRow(),
> table.Rows.Add(tr), new TableCell(), new Label(), label.Text = SomeDBValue
;
> cell.Controls.Add(label), row.Cells.Add(cell)...), which is far harder to
> maintain and change than the examples below.
> The code has pretty good abstraction
> 1 - it uses methods located in codebehind for any actual processing
> 2 - It uses DataBinder.Eval which abstracts away the business layer
> implementation (is Container.DataItem a datarowview ora custom class? who
> knows, and why should the presentation layer care?)
> I think you'll find that the benefits of further separation aren't worth
> the high price you'll end up paying
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
> "Joe" <Joe@.discussions.microsoft.com> wrote in message
> news:65EF2A6E-0440-4DFC-B8B5-AE49C4C8BBA1@.microsoft.com...
>
>

Seperating code from HTML markup

Hello All:

I am writing to ask for your opinions. I have a colleague who combines his
code with the markup used to display the code (reckoning back to classic
ASP). Here's an example of a datagrid column:

<asp:TemplateColumn>
<ItemStyle CssClass="TableData" Width="15%"></ItemStyle>
<ItemTemplate>
<a href="http://links.10026.com/?link=<%# ShowURL(DataBinder.Eval(Container.DataItem,
"FORM_ID"))%>" target="_blank">
<%# DataBinder.Eval(Container.DataItem, "FORM_NUMBER")%></a>
</ItemTemplate>
</asp:TemplateColumn
or another column

<asp:TemplateColumn>
<ItemStyle CssClass="TableData" Width="20%"></ItemStyle>
<ItemTemplate>
<%# DisplayState(DataBinder.EvalContainer.DataItem,
"FORM_STATE_CD"))%>
</ItemTemplate>
</asp:TemplateColumn
Where ShowURL and DisplayState are defined in the code-behind. We have the
restriction that we can not use ViewState when creating our webforms
(security breach due to how they have architected their web app). I wonder
if there is a bettre way to do this.

In my opinion, this is sloppy programming. I, however, could be wrong.
Maybe this is the best way to do this. So I am asking:

What is your opinion regarding mixiing content and functionality.

If you think that this could have been done differnetly, What would you have
done? Is there a better way to do this?

Finally, the IDE will not display the Design View of the page that contains
this markup. The message says "Could not open in Design View. Quote values
differently inside of a '<% ...value... %>' block."

Thank you for your input.
--
JoeAs for the designer error, simply switching:
a href="http://links.10026.com/?link=<%# ShowURL(DataBinder.Eval(Container.DataItem, "FORM_ID"))%>"
target="_blank"
to:

a href='<%# ShowURL(DataBinder.Eval(Container.DataItem, "FORM_ID"))%>'
target="_blank"
should solve that (replace the " around the <%# ... %> with ' )

As far as I'm concerned, the question is pretty trivial. The separation of
code and HTML is almost complete in your examples below. ShowURL and
DisplayState both represent functionality that resides outside the HTML, and
if it needs to be reused, it could easily be extracted to a seperate code
file. The only way to achieve even greater separation is to hook into the
OnItemDataBound event and write a considerable chunk of code. For any
complex binding, this will result in a lot of code generating HTML. I've
seen code that took this approach, and it's an absolute nightmare. You end
with huge amounts of html created in code (new Table(), new TableRow(),
table.Rows.Add(tr), new TableCell(), new Label(), label.Text = SomeDBValue;
cell.Controls.Add(label), row.Cells.Add(cell)...), which is far harder to
maintain and change than the examples below.

The code has pretty good abstraction

1 - it uses methods located in codebehind for any actual processing
2 - It uses DataBinder.Eval which abstracts away the business layer
implementation (is Container.DataItem a datarowview ora custom class? who
knows, and why should the presentation layer care?)

I think you'll find that the benefits of further separation aren't worth
the high price you'll end up paying

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/

"Joe" <Joe@.discussions.microsoft.com> wrote in message
news:65EF2A6E-0440-4DFC-B8B5-AE49C4C8BBA1@.microsoft.com...
> Hello All:
> I am writing to ask for your opinions. I have a colleague who combines
> his
> code with the markup used to display the code (reckoning back to classic
> ASP). Here's an example of a datagrid column:
> <asp:TemplateColumn>
> <ItemStyle CssClass="TableData" Width="15%"></ItemStyle>
> <ItemTemplate>
> <a href="http://links.10026.com/?link=<%# ShowURL(DataBinder.Eval(Container.DataItem,
> "FORM_ID"))%>" target="_blank">
> <%# DataBinder.Eval(Container.DataItem, "FORM_NUMBER")%></a>
> </ItemTemplate>
> </asp:TemplateColumn>
> or another column
> <asp:TemplateColumn>
> <ItemStyle CssClass="TableData" Width="20%"></ItemStyle>
> <ItemTemplate>
> <%# DisplayState(DataBinder.EvalContainer.DataItem,
> "FORM_STATE_CD"))%>
> </ItemTemplate>
> </asp:TemplateColumn>
> Where ShowURL and DisplayState are defined in the code-behind. We have
> the
> restriction that we can not use ViewState when creating our webforms
> (security breach due to how they have architected their web app). I
> wonder
> if there is a bettre way to do this.
> In my opinion, this is sloppy programming. I, however, could be wrong.
> Maybe this is the best way to do this. So I am asking:
> What is your opinion regarding mixiing content and functionality.
> If you think that this could have been done differnetly, What would you
> have
> done? Is there a better way to do this?
> Finally, the IDE will not display the Design View of the page that
> contains
> this markup. The message says "Could not open in Design View. Quote
> values
> differently inside of a '<% ...value... %>' block."
> Thank you for your input.
> --
> Joe
Thank you Karl. This helped. As always, I appreciate your input.
--
Joe

"Karl Seguin [MVP]" wrote:

> As for the designer error, simply switching:
> a href="http://links.10026.com/?link=<%# ShowURL(DataBinder.Eval(Container.DataItem, "FORM_ID"))%>"
> target="_blank">
> to:
> a href='<%# ShowURL(DataBinder.Eval(Container.DataItem, "FORM_ID"))%>'
> target="_blank">
> should solve that (replace the " around the <%# ... %> with ' )
> As far as I'm concerned, the question is pretty trivial. The separation of
> code and HTML is almost complete in your examples below. ShowURL and
> DisplayState both represent functionality that resides outside the HTML, and
> if it needs to be reused, it could easily be extracted to a seperate code
> file. The only way to achieve even greater separation is to hook into the
> OnItemDataBound event and write a considerable chunk of code. For any
> complex binding, this will result in a lot of code generating HTML. I've
> seen code that took this approach, and it's an absolute nightmare. You end
> with huge amounts of html created in code (new Table(), new TableRow(),
> table.Rows.Add(tr), new TableCell(), new Label(), label.Text = SomeDBValue;
> cell.Controls.Add(label), row.Cells.Add(cell)...), which is far harder to
> maintain and change than the examples below.
> The code has pretty good abstraction
> 1 - it uses methods located in codebehind for any actual processing
> 2 - It uses DataBinder.Eval which abstracts away the business layer
> implementation (is Container.DataItem a datarowview ora custom class? who
> knows, and why should the presentation layer care?)
> I think you'll find that the benefits of further separation aren't worth
> the high price you'll end up paying
> Karl
> --
> http://www.openmymind.net/
> http://www.fuelindustries.com/
>
> "Joe" <Joe@.discussions.microsoft.com> wrote in message
> news:65EF2A6E-0440-4DFC-B8B5-AE49C4C8BBA1@.microsoft.com...
> > Hello All:
> > I am writing to ask for your opinions. I have a colleague who combines
> > his
> > code with the markup used to display the code (reckoning back to classic
> > ASP). Here's an example of a datagrid column:
> > <asp:TemplateColumn>
> > <ItemStyle CssClass="TableData" Width="15%"></ItemStyle>
> > <ItemTemplate>
> > <a href="http://links.10026.com/?link=<%# ShowURL(DataBinder.Eval(Container.DataItem,
> > "FORM_ID"))%>" target="_blank">
> > <%# DataBinder.Eval(Container.DataItem, "FORM_NUMBER")%></a>
> > </ItemTemplate>
> > </asp:TemplateColumn>
> > or another column
> > <asp:TemplateColumn>
> > <ItemStyle CssClass="TableData" Width="20%"></ItemStyle>
> > <ItemTemplate>
> > <%# DisplayState(DataBinder.EvalContainer.DataItem,
> > "FORM_STATE_CD"))%>
> > </ItemTemplate>
> > </asp:TemplateColumn>
> > Where ShowURL and DisplayState are defined in the code-behind. We have
> > the
> > restriction that we can not use ViewState when creating our webforms
> > (security breach due to how they have architected their web app). I
> > wonder
> > if there is a bettre way to do this.
> > In my opinion, this is sloppy programming. I, however, could be wrong.
> > Maybe this is the best way to do this. So I am asking:
> > What is your opinion regarding mixiing content and functionality.
> > If you think that this could have been done differnetly, What would you
> > have
> > done? Is there a better way to do this?
> > Finally, the IDE will not display the Design View of the page that
> > contains
> > this markup. The message says "Could not open in Design View. Quote
> > values
> > differently inside of a '<% ...value... %>' block."
> > Thank you for your input.
> > --
> > Joe
>