Showing posts with label server. Show all posts
Showing posts with label server. Show all posts

Thursday, March 29, 2012

newbie: inserting data into sql form writes only null values

Hi,

using VStudio 2005/sql server 2005

Have a simple web form that inserts the results in a table. It seems to
write to the table, but not the values from the asp forms fields. It adds a
new record and increments the id field by one -- but in all the other
fields, it merely writes Null to the fields. He are some other points:

I am not inserting data into every field -- for test purposes I am only
using 4 fields.
The id field is NOT one of the fields on the asp form -- although it is the
only field that actually writes a correct value

here's the code:using VStudio 2005/sql server 2005

Have a simple web form that inserts the results in a table. It seems to
write to the table, but not the values from the asp forms fields. It adds a
new record and increments the id field by one -- but in all the other
fields, it merely writes Null to the fields. He are some other points:

I am not inserting data into every field -- for test purposes I am only
using 4 fields.
The id field is NOT one of the fields on the asp form -- although it is the
only field that actually writes a correct value

here's the code:

<asp:TextBox ID="FirstName" runat="server"></asp:TextBox><br />
Last name:
<asp:TextBox ID="LastName" runat="server"></asp:TextBox><br />
Address:
<asp:TextBox ID="Address" runat="server"></asp:TextBox><br />
City:
<asp:TextBox ID="City" runat="server"></asp:TextBox><br />
Year created:
<asp:DropDownList ID="YearCreated" runat="server">
</asp:DropDownList><br />

<asp:Button ID="Save" runat="server" Text="Save" />
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString=
"<%$ ConnectionStrings:WHCConnectionString %>"
InsertCommand=
"INSERT INTO
[artsfestival] ([lastName], [firstName], [address], [city])
VALUES
(@.lastName, @.firstName, @.address, @.city)">
<InsertParameters>
<asp:FormParameter Name="lastName" Type="String"
FormField="LastName" />
<asp:FormParameter Name="firstName" Type="String"
FormField="FirstName" />
<asp:FormParameter Name="address" Type="String"
FormField="Address" />
<asp:FormParameter Name="city" Type="String"
FormField="City" />
</InsertParameters>
</asp:SqlDataSource>

"thersitz" <thersitz@.gmail.comwrote in message
news:OhRMtSXRHHA.2256@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Hi,
>
using VStudio 2005/sql server 2005
>
Have a simple web form that inserts the results in a table. It seems to
write to the table, but not the values from the asp forms fields. It adds
a new record and increments the id field by one -- but in all the other
fields, it merely writes Null to the fields. He are some other points:
>
I am not inserting data into every field -- for test purposes I am only
using 4 fields.
The id field is NOT one of the fields on the asp form -- although it is
the only field that actually writes a correct value
>
here's the code:
>
>


Hi there,

Use

ControlParameter instead of FormParameter. The difference is that
FormParameter takes its value directly from Request.Form collection using the
name given by FormField. The problem with your vode is that, textbox does not
post its value in Request.Form[textBox.ID] but in
Request.Form[textBox.UniqueID] which reflects IDs of the parent controls.
Change you insertparameters declaration to:

<InsertParameters>
<asp:ControlParameter Name="lastName" Type="String" ControlID="LastName"
PropertyName="Text"/>
<asp:ControlParameter Name="firstName" ControlID="FirstName" Type="String"
PropertyName="Text"/>
<asp:ControlParameter Name="address" Type="String" ControlID="Address"
PropertyName="Text"/>
<asp:ControlParameter Name="city" Type="String" ControlID="City"
PropertyName="Text"/>
</InsertParameters>

--
Milosz

"thersitz" wrote:

Quote:

Originally Posted by

using VStudio 2005/sql server 2005
>
Have a simple web form that inserts the results in a table. It seems to
write to the table, but not the values from the asp forms fields. It adds a
new record and increments the id field by one -- but in all the other
fields, it merely writes Null to the fields. He are some other points:
>
I am not inserting data into every field -- for test purposes I am only
using 4 fields.
The id field is NOT one of the fields on the asp form -- although it is the
only field that actually writes a correct value
>
here's the code:
>
<asp:TextBox ID="FirstName" runat="server"></asp:TextBox><br />
Last name:
<asp:TextBox ID="LastName" runat="server"></asp:TextBox><br />
Address:
<asp:TextBox ID="Address" runat="server"></asp:TextBox><br />
City:
<asp:TextBox ID="City" runat="server"></asp:TextBox><br />
Year created:
<asp:DropDownList ID="YearCreated" runat="server">
</asp:DropDownList><br />
>
<asp:Button ID="Save" runat="server" Text="Save" />
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString=
"<%$ ConnectionStrings:WHCConnectionString %>"
InsertCommand=
"INSERT INTO
[artsfestival] ([lastName], [firstName], [address], [city])
VALUES
(@.lastName, @.firstName, @.address, @.city)">
<InsertParameters>
<asp:FormParameter Name="lastName" Type="String"
FormField="LastName" />
<asp:FormParameter Name="firstName" Type="String"
FormField="FirstName" />
<asp:FormParameter Name="address" Type="String"
FormField="Address" />
<asp:FormParameter Name="city" Type="String"
FormField="City" />
</InsertParameters>
</asp:SqlDataSource>
>
>
>
>
"thersitz" <thersitz@.gmail.comwrote in message
news:OhRMtSXRHHA.2256@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Hi,

using VStudio 2005/sql server 2005

Have a simple web form that inserts the results in a table. It seems to
write to the table, but not the values from the asp forms fields. It adds
a new record and increments the id field by one -- but in all the other
fields, it merely writes Null to the fields. He are some other points:

I am not inserting data into every field -- for test purposes I am only
using 4 fields.
The id field is NOT one of the fields on the asp form -- although it is
the only field that actually writes a correct value

here's the code:


>
>
>


Thanks Milosz, it worked.

I'm confused why the book had me use the FormParameter and FormFieldID --
but thanks for getting me past this point.

Take care.

"Milosz Skalecki [MCAD]" <mily242@.REMOVEITwp.plwrote in message
news:1206D448-EDF2-419B-9A48-D05F7B51FAAF@.microsoft.com...

Quote:

Originally Posted by

Hi there,
>
Use
>
ControlParameter instead of FormParameter. The difference is that
FormParameter takes its value directly from Request.Form collection using
the
name given by FormField. The problem with your vode is that, textbox does
not
post its value in Request.Form[textBox.ID] but in
Request.Form[textBox.UniqueID] which reflects IDs of the parent controls.
Change you insertparameters declaration to:
>
<InsertParameters>
<asp:ControlParameter Name="lastName" Type="String" ControlID="LastName"
PropertyName="Text"/>
<asp:ControlParameter Name="firstName" ControlID="FirstName" Type="String"
PropertyName="Text"/>
<asp:ControlParameter Name="address" Type="String" ControlID="Address"
PropertyName="Text"/>
<asp:ControlParameter Name="city" Type="String" ControlID="City"
PropertyName="Text"/>
</InsertParameters>
>
--
Milosz
>
>
"thersitz" wrote:
>

Quote:

Originally Posted by

> using VStudio 2005/sql server 2005
>>
>Have a simple web form that inserts the results in a table. It seems to
>write to the table, but not the values from the asp forms fields. It adds
>a
>new record and increments the id field by one -- but in all the other
>fields, it merely writes Null to the fields. He are some other points:
>>
>I am not inserting data into every field -- for test purposes I am only
>using 4 fields.
>The id field is NOT one of the fields on the asp form -- although it is
>the
>only field that actually writes a correct value
>>
>here's the code:
>>
> <asp:TextBox ID="FirstName" runat="server"></asp:TextBox><br />
> Last name:
> <asp:TextBox ID="LastName" runat="server"></asp:TextBox><br />
> Address:
> <asp:TextBox ID="Address" runat="server"></asp:TextBox><br />
> City:
> <asp:TextBox ID="City" runat="server"></asp:TextBox><br />
> Year created:
> <asp:DropDownList ID="YearCreated" runat="server">
> </asp:DropDownList><br />
>>
> <asp:Button ID="Save" runat="server" Text="Save" />
> </div>
> <asp:SqlDataSource ID="SqlDataSource1" runat="server"
> ConnectionString=
> "<%$ ConnectionStrings:WHCConnectionString %>"
> InsertCommand=
> "INSERT INTO
> [artsfestival] ([lastName], [firstName], [address], [city])
> VALUES
> (@.lastName, @.firstName, @.address, @.city)">
> <InsertParameters>
> <asp:FormParameter Name="lastName" Type="String"
> FormField="LastName" />
> <asp:FormParameter Name="firstName" Type="String"
> FormField="FirstName" />
> <asp:FormParameter Name="address" Type="String"
> FormField="Address" />
> <asp:FormParameter Name="city" Type="String"
> FormField="City" />
> </InsertParameters>
> </asp:SqlDataSource>
>>
>>
>>
>>
>"thersitz" <thersitz@.gmail.comwrote in message
>news:OhRMtSXRHHA.2256@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Hi,
>
using VStudio 2005/sql server 2005
>
Have a simple web form that inserts the results in a table. It seems to
write to the table, but not the values from the asp forms fields. It
adds
a new record and increments the id field by one -- but in all the other
fields, it merely writes Null to the fields. He are some other points:
>
I am not inserting data into every field -- for test purposes I am only
using 4 fields.
The id field is NOT one of the fields on the asp form -- although it is
the only field that actually writes a correct value
>
here's the code:
>
>


>>
>>
>>

newbie: inserting data into sql form writes only null values

Hi,
using VStudio 2005/sql server 2005
Have a simple web form that inserts the results in a table. It seems to
write to the table, but not the values from the asp forms fields. It adds a
new record and increments the id field by one -- but in all the other
fields, it merely writes Null to the fields. He are some other points:
I am not inserting data into every field -- for test purposes I am only
using 4 fields.
The id field is NOT one of the fields on the asp form -- although it is the
only field that actually writes a correct value
here's the code:using VStudio 2005/sql server 2005
Have a simple web form that inserts the results in a table. It seems to
write to the table, but not the values from the asp forms fields. It adds a
new record and increments the id field by one -- but in all the other
fields, it merely writes Null to the fields. He are some other points:
I am not inserting data into every field -- for test purposes I am only
using 4 fields.
The id field is NOT one of the fields on the asp form -- although it is the
only field that actually writes a correct value
here's the code:
<asp:TextBox ID="FirstName" runat="server"></asp:TextBox><br />
Last name:
<asp:TextBox ID="LastName" runat="server"></asp:TextBox><br />
Address:
<asp:TextBox ID="Address" runat="server"></asp:TextBox><br />
City:
<asp:TextBox ID="City" runat="server"></asp:TextBox><br />
Year created:
<asp:DropDownList ID="YearCreated" runat="server">
</asp:DropDownList><br />
<asp:Button ID="Save" runat="server" Text="Save" />
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString=
"<%$ ConnectionStrings:WHCConnectionString %>"
InsertCommand=
"INSERT INTO
[artsfestival] ([lastName], [firstName], [address], [city])
VALUES
(@.lastName, @.firstName, @.address, @.city)">
<InsertParameters>
<asp:FormParameter Name="lastName" Type="String"
FormField="LastName" />
<asp:FormParameter Name="firstName" Type="String"
FormField="FirstName" />
<asp:FormParameter Name="address" Type="String"
FormField="Address" />
<asp:FormParameter Name="city" Type="String"
FormField="City" />
</InsertParameters>
</asp:SqlDataSource>
"thersitz" <thersitz@.gmail.com> wrote in message
news:OhRMtSXRHHA.2256@.TK2MSFTNGP02.phx.gbl...
> Hi,
> using VStudio 2005/sql server 2005
> Have a simple web form that inserts the results in a table. It seems to
> write to the table, but not the values from the asp forms fields. It adds
> a new record and increments the id field by one -- but in all the other
> fields, it merely writes Null to the fields. He are some other points:
> I am not inserting data into every field -- for test purposes I am only
> using 4 fields.
> The id field is NOT one of the fields on the asp form -- although it is
> the only field that actually writes a correct value
> here's the code:
>
Hi there,
Use
ControlParameter instead of FormParameter. The difference is that
FormParameter takes its value directly from Request.Form collection using th
e
name given by FormField. The problem with your vode is that, textbox does no
t
post its value in Request.Form[textBox.ID] but in
Request.Form[textBox.UniqueID] which reflects IDs of the parent controls.
Change you insertparameters declaration to:
<InsertParameters>
<asp:ControlParameter Name="lastName" Type="String" ControlID="LastName"
PropertyName="Text"/>
<asp:ControlParameter Name="firstName" ControlID="FirstName" Type="String"
PropertyName="Text"/>
<asp:ControlParameter Name="address" Type="String" ControlID="Address"
PropertyName="Text"/>
<asp:ControlParameter Name="city" Type="String" ControlID="City"
PropertyName="Text"/>
</InsertParameters>
Milosz
"thersitz" wrote:

> using VStudio 2005/sql server 2005
> Have a simple web form that inserts the results in a table. It seems to
> write to the table, but not the values from the asp forms fields. It adds
a
> new record and increments the id field by one -- but in all the other
> fields, it merely writes Null to the fields. He are some other points:
> I am not inserting data into every field -- for test purposes I am only
> using 4 fields.
> The id field is NOT one of the fields on the asp form -- although it is th
e
> only field that actually writes a correct value
> here's the code:
> <asp:TextBox ID="FirstName" runat="server"></asp:TextBox><br />
> Last name:
> <asp:TextBox ID="LastName" runat="server"></asp:TextBox><br />
> Address:
> <asp:TextBox ID="Address" runat="server"></asp:TextBox><br />
> City:
> <asp:TextBox ID="City" runat="server"></asp:TextBox><br />
> Year created:
> <asp:DropDownList ID="YearCreated" runat="server">
> </asp:DropDownList><br />
> <asp:Button ID="Save" runat="server" Text="Save" />
> </div>
> <asp:SqlDataSource ID="SqlDataSource1" runat="server"
> ConnectionString=
> "<%$ ConnectionStrings:WHCConnectionString %>"
> InsertCommand=
> "INSERT INTO
> [artsfestival] ([lastName], [firstName], [address], [city])
> VALUES
> (@.lastName, @.firstName, @.address, @.city)">
> <InsertParameters>
> <asp:FormParameter Name="lastName" Type="String"
> FormField="LastName" />
> <asp:FormParameter Name="firstName" Type="String"
> FormField="FirstName" />
> <asp:FormParameter Name="address" Type="String"
> FormField="Address" />
> <asp:FormParameter Name="city" Type="String"
> FormField="City" />
> </InsertParameters>
> </asp:SqlDataSource>
>
>
> "thersitz" <thersitz@.gmail.com> wrote in message
> news:OhRMtSXRHHA.2256@.TK2MSFTNGP02.phx.gbl...
>
>
Thanks Milosz, it worked.
I'm why the book had me use the FormParameter and FormFieldID --
but thanks for getting me past this point.
Take care.
"Milosz Skalecki [MCAD]" <mily242@.REMOVEITwp.pl> wrote in message
news:1206D448-EDF2-419B-9A48-D05F7B51FAAF@.microsoft.com...
> Hi there,
> Use
> ControlParameter instead of FormParameter. The difference is that
> FormParameter takes its value directly from Request.Form collection using
> the
> name given by FormField. The problem with your vode is that, textbox does
> not
> post its value in Request.Form[textBox.ID] but in
> Request.Form[textBox.UniqueID] which reflects IDs of the parent controls.
> Change you insertparameters declaration to:
> <InsertParameters>
> <asp:ControlParameter Name="lastName" Type="String" ControlID="LastName"
> PropertyName="Text"/>
> <asp:ControlParameter Name="firstName" ControlID="FirstName" Type="String"
> PropertyName="Text"/>
> <asp:ControlParameter Name="address" Type="String" ControlID="Address"
> PropertyName="Text"/>
> <asp:ControlParameter Name="city" Type="String" ControlID="City"
> PropertyName="Text"/>
> </InsertParameters>
> --
> Milosz
>
> "thersitz" wrote:
>

Newbie: Javascript help

What js code is required to automatically submit a page to the server when a
user enters a given character (say "?") into a textbox server control please?

Thank youIn the .aspx page (did not check it running):

<head>
...
function checkKey(){
if (window.event.keyCode==63)
myForm.submit();
else
return true;
}
...
</head>
<body>
<form id=myForm ...?>
...
<asp:textbox ... onkeypress="return checkKey();" ... />
...
</form></body
Eliyahu

"MikeH" <MikeH@.community.nospam> wrote in message
news:BE91A000-8D92-448E-9B03-CC531DF85F8D@.microsoft.com...
> What js code is required to automatically submit a page to the server when
a
> user enters a given character (say "?") into a textbox server control
please?
> Thank you

Monday, March 26, 2012

Newbie: pages working only above the root

It does rather sound like the server isn't setup correctly.
If ASPX pages are not working in the root of the site, then it could be that
IIS doesn't have the correct script mappings setup.

Asking the ISP to run aspnet_regiis -r and aspnet_regiis -c may fix the
problem by reconfiguring the IIS script mappings, and redeploying the client
script files to each application folder.

--
Regards

Tim Stephenson MCSD.NET
Charted MCAD & MCSD.NET Early Achiever

"James Campbell" <james@dotnet.itags.org.stuttersystems.com> wrote in message
news:O5NW9idkDHA.2616@dotnet.itags.org.TK2MSFTNGP11.phx.gbl...
> I have a site hosted with a company in the US who it seems have given me a
> dedicated server for one of my sites:
> http://216.133.81.184/
> 1. Firstly, I can upload files to the wwwroot (directly into the root) as
> this seems to be set as the home directory
> a. Is this the right way to do it, as I have never seen this before
?
> 2. Classic ASP works in the root: http://216.133.81.184/test.asp
> 3. asp.net (using vb) does not work in the root:
> http://216.133.81.184/hello3.aspx
> 4. But does asp.net works in a sub folder:
> http://216.133.81.184/carresa_site/hello3.aspx
> Has the .net framework been installed properly ?
> Have the host setup the server correctly ??
> Any ideas would be appreciated.
> Thanks
> James CampbellHi Tim,

Thanks for the reply. I have spoke to a few people now about this and your
comments echo everybody else's.

"host misconfiguration"

Thanks
James

"Tim Stephenson" <tim.stephenson@.archant.co.uk> wrote in message
news:e5UePWwkDHA.2364@.TK2MSFTNGP11.phx.gbl...
> It does rather sound like the server isn't setup correctly.
> If ASPX pages are not working in the root of the site, then it could be
that
> IIS doesn't have the correct script mappings setup.
> Asking the ISP to run aspnet_regiis -r and aspnet_regiis -c may fix the
> problem by reconfiguring the IIS script mappings, and redeploying the
client
> script files to each application folder.
> --
> Regards
> Tim Stephenson MCSD.NET
> Charted MCAD & MCSD.NET Early Achiever
>
> "James Campbell" <james@.stuttersystems.com> wrote in message
> news:O5NW9idkDHA.2616@.TK2MSFTNGP11.phx.gbl...
> > I have a site hosted with a company in the US who it seems have given me
a
> > dedicated server for one of my sites:
> > http://216.133.81.184/
> > 1. Firstly, I can upload files to the wwwroot (directly into the root)
as
> > this seems to be set as the home directory
> > a. Is this the right way to do it, as I have never seen this before
> ?
> > 2. Classic ASP works in the root: http://216.133.81.184/test.asp
> > 3. asp.net (using vb) does not work in the root:
> > http://216.133.81.184/hello3.aspx
> > 4. But does asp.net works in a sub folder:
> > http://216.133.81.184/carresa_site/hello3.aspx
> > Has the .net framework been installed properly ?
> > Have the host setup the server correctly ??
> > Any ideas would be appreciated.
> > Thanks
> > James Campbell

Newbie: Propably simple answer Checkbox_checked?

Hi there

I what to test a stored procedures on a web page using the normal connection
string.
the controls: Server, username,Password, database allow to select the
appropriate Sql server database.
Now I would use checkbox = Trusted connection as option to logon to the
database.

I guess the question that I have is where am I going wrong in the code?
How can I step through the script before or up until the page is loaded?

Any hints are greatly appreciated, the same will be made available after
completion.

Regards

Norman

Here is the Code:-----------------
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="True" %>
<%@dotnet.itags.org. import Namespace="System.Data" %>
<%@dotnet.itags.org. import Namespace="System.Data.SqlClient" %>
<%@dotnet.itags.org. import Namespace="System.Web.UI.WebControls" %>
<HTML>
<HEAD>
<script runat="server"
' code to check if the tickbox was ticked

Sub Check_Clicked(sender As Object, e As EventArgs)

If WinTrusted.checked then
'Dim conn As New SqlConnection( _
' "Data source=" & DatabaseServer.Text & _
' ";Trusted_Connection=true" & _
' ";Initial catalog=" & Database.Text)
'else
'Dim conn As New SqlConnection( _
' "Data source=" & DatabaseServer.Text & _
' ";Trusted_Connection=true" & _
' ";Initial catalog=" & Database.Text)
end if
End Sub
'
Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ds As New DataSet
Dim conn As New SqlConnection( _
"Data source=" & DatabaseServer.Text & _
";Trusted_Connection=true" & _
";Initial catalog=" & Database.Text)

Dim cmd As New SqlCommand("sp_stored_procedures", conn) ' << when Sub
Check_Clicked and the code is run Asp courses an error at this line saying
that "conn" is not defined??
Dim adpt As New SqlDataAdapter(cmd)
Try
Status.Text = ""
adpt.Fill(ds, "SPs")
SPs.DataSource = ds.Tables("SPs")
SPs.DataTextField = "PROCEDURE_NAME"
SPs.DataBind()
Catch ex As SqlException
Status.Text = ex.Message
End Try
End Sub
Sub GetParametersButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ds As New DataSet
'If Wintrusted.checked = True Then
' Dim conn As New SqlConnection( _
' "Data source=" & DatabaseServer.Text & _
' ";Trusted_Connection=true" & _
' ";Initial catalog=" & Database.Text)
'Else
Dim conn As New SqlConnection( _
"Data source=" & DatabaseServer.Text & _
";User id=" & Userid.text & _
";Password=" & Password.Text & _
";Initial catalog=" & Database.Text)
'End If
Dim cmd As New SqlCommand("sp_sproc_columns", conn) '' << when Sub
Check_Clicked and the code is run Asp courses an error at this line saying
that "conn" is not defined??
Dim adpt As New SqlDataAdapter(cmd)
Try
Status.Text = ""
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("@dotnet.itags.org.procedure_name", SqlDbType.NVarchar, 390).Value = _
SPs.SelectedItem.Value
adpt.Fill(ds, "Parameters")
ParametersDataGrid.DataSource = ds.Tables("Parameters")
ParametersDataGrid.DataBind()
ResultsDataGrid.Visible = False
Catch ex As SqlException
Status.Text = ex.Message
End Try
End Sub

Sub AddParameters(ByVal cmd As SqlCommand)
'works ok
End Sub

Sub UpdateParameters(ByVal cmd As SqlCommand)
'Works Ok
End Sub

Sub ExecuteQueryButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim ds As New DataSet
'If WinTrusted.checked then
'Dim conn As New SqlConnection( _
' "Data source=" & DatabaseServer.Text & _
' ";Trusted_Connection=true" & _
' ";Initial catalog=" & Database.Text)
'else
Dim conn As New SqlConnection( _
"Data source=" & DatabaseServer.Text & _
";Trusted_Connection=true" & _
";Initial catalog=" & Database.Text)
'end if
Dim cmd As New SqlCommand(SPs.SelectedItem.Value, conn) ' ' << when Sub
Check_Clicked and the code is run Asp courses an error at this line saying
that "conn" is not defined??
Dim adpt As New SqlDataAdapter(cmd)
Try
Status.Text = ""
cmd.CommandType = CommandType.StoredProcedure
AddParameters(cmd)
adpt.Fill(ds, "Results")
UpdateParameters(cmd)
ResultsDataGrid.DataSource = ds.Tables("Results")
ResultsDataGrid.DataBind()
ResultsDataGrid.Visible = True
Catch ex As SqlException
Status.Text = ex.Message
End Try
End Sub
</script>
</HEAD>
----------End of
Code--------------You problem i think is happening because you are defining the connection in
a if statement
that would make it a local variable of
if(conditional statement)
{
// you code and your variables.
// any variables declared here are local to this if statement..
}

try
SqlConnection conn;
if(WinTrusted.checked == true)
con = new SqlConnection("con paramas")
else
con = new SqlConnection("second set of param")
}
SqlDataAdapter myCommand = new SqlDataAdapter("sp_storedproc", myCon)
myCommand.SelectCommand.CommandType = CommandType.StoredProc

This should work,

Hermit Dave

"Norman Fritag" <mtp.net@.ozemail.com.au> wrote in message
news:cY6Cb.10$Tq.1083@.nnrp1.ozemail.com.au...
> Hi there
> I what to test a stored procedures on a web page using the normal
connection
> string.
> the controls: Server, username,Password, database allow to select the
> appropriate Sql server database.
> Now I would use checkbox = Trusted connection as option to logon to the
> database.
> I guess the question that I have is where am I going wrong in the code?
> How can I step through the script before or up until the page is loaded?
> Any hints are greatly appreciated, the same will be made available after
> completion.
> Regards
> Norman
>
> Here is the Code:-----------------
> <%@. Page Language="VB" AutoEventWireup="True" %>
> <%@. import Namespace="System.Data" %>
> <%@. import Namespace="System.Data.SqlClient" %>
> <%@. import Namespace="System.Web.UI.WebControls" %>
> <HTML>
> <HEAD>
> <script runat="server">
> ' code to check if the tickbox was ticked
> Sub Check_Clicked(sender As Object, e As EventArgs)
> If WinTrusted.checked then
> 'Dim conn As New SqlConnection( _
> ' "Data source=" & DatabaseServer.Text & _
> ' ";Trusted_Connection=true" & _
> ' ";Initial catalog=" & Database.Text)
> 'else
> 'Dim conn As New SqlConnection( _
> ' "Data source=" & DatabaseServer.Text & _
> ' ";Trusted_Connection=true" & _
> ' ";Initial catalog=" & Database.Text)
> end if
> End Sub
> '
> Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
> Dim ds As New DataSet
> Dim conn As New SqlConnection( _
> "Data source=" & DatabaseServer.Text & _
> ";Trusted_Connection=true" & _
> ";Initial catalog=" & Database.Text)
> Dim cmd As New SqlCommand("sp_stored_procedures", conn) ' << when Sub
> Check_Clicked and the code is run Asp courses an error at this line saying
> that "conn" is not defined??
> Dim adpt As New SqlDataAdapter(cmd)
> Try
> Status.Text = ""
> adpt.Fill(ds, "SPs")
> SPs.DataSource = ds.Tables("SPs")
> SPs.DataTextField = "PROCEDURE_NAME"
> SPs.DataBind()
> Catch ex As SqlException
> Status.Text = ex.Message
> End Try
> End Sub
> Sub GetParametersButton_Click(ByVal sender As Object, ByVal e As
EventArgs)
> Dim ds As New DataSet
> 'If Wintrusted.checked = True Then
> ' Dim conn As New SqlConnection( _
> ' "Data source=" & DatabaseServer.Text & _
> ' ";Trusted_Connection=true" & _
> ' ";Initial catalog=" & Database.Text)
> 'Else
> Dim conn As New SqlConnection( _
> "Data source=" & DatabaseServer.Text & _
> ";User id=" & Userid.text & _
> ";Password=" & Password.Text & _
> ";Initial catalog=" & Database.Text)
> 'End If
> Dim cmd As New SqlCommand("sp_sproc_columns", conn) '' << when Sub
> Check_Clicked and the code is run Asp courses an error at this line saying
> that "conn" is not defined??
> Dim adpt As New SqlDataAdapter(cmd)
> Try
> Status.Text = ""
> cmd.CommandType = CommandType.StoredProcedure
> cmd.Parameters.Add("@.procedure_name", SqlDbType.NVarchar, 390).Value = _
> SPs.SelectedItem.Value
> adpt.Fill(ds, "Parameters")
> ParametersDataGrid.DataSource = ds.Tables("Parameters")
> ParametersDataGrid.DataBind()
> ResultsDataGrid.Visible = False
> Catch ex As SqlException
> Status.Text = ex.Message
> End Try
> End Sub
> Sub AddParameters(ByVal cmd As SqlCommand)
> 'works ok
> End Sub
> Sub UpdateParameters(ByVal cmd As SqlCommand)
> 'Works Ok
> End Sub
> Sub ExecuteQueryButton_Click(ByVal sender As Object, ByVal e As EventArgs)
> Dim ds As New DataSet
> 'If WinTrusted.checked then
> 'Dim conn As New SqlConnection( _
> ' "Data source=" & DatabaseServer.Text & _
> ' ";Trusted_Connection=true" & _
> ' ";Initial catalog=" & Database.Text)
> 'else
> Dim conn As New SqlConnection( _
> "Data source=" & DatabaseServer.Text & _
> ";Trusted_Connection=true" & _
> ";Initial catalog=" & Database.Text)
> 'end if
> Dim cmd As New SqlCommand(SPs.SelectedItem.Value, conn) ' ' << when Sub
> Check_Clicked and the code is run Asp courses an error at this line saying
> that "conn" is not defined??
> Dim adpt As New SqlDataAdapter(cmd)
> Try
> Status.Text = ""
> cmd.CommandType = CommandType.StoredProcedure
> AddParameters(cmd)
> adpt.Fill(ds, "Results")
> UpdateParameters(cmd)
> ResultsDataGrid.DataSource = ds.Tables("Results")
> ResultsDataGrid.DataBind()
> ResultsDataGrid.Visible = True
> Catch ex As SqlException
> Status.Text = ex.Message
> End Try
> End Sub
> </script>
> </HEAD>
> ----------End of
> Code--------------
Sorry bout the typos... too knackered... and too hungry and i would do with
some food and some sleep...

Your problem i think is happening because you are defining the connection in
a if statement
that would make it a local variable of
if(conditional statement)
{
// you code and your variables.
// any variables declared here are local to this if statement..
}

try
SqlConnection conn;
if(WinTrusted.checked == true)
conn = new SqlConnection("con paramas")
else
conn = new SqlConnection("second set of param")
}
SqlDataAdapter myCommand = new SqlDataAdapter("sp_storedproc", conn)
myCommand.SelectCommand.CommandType = CommandType.StoredProc

This should work,

Hermit Dave

"Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
news:evdi6$DwDHA.2372@.TK2MSFTNGP09.phx.gbl...
> You problem i think is happening because you are defining the connection
in
> a if statement
> that would make it a local variable of
> if(conditional statement)
> {
> // you code and your variables.
> // any variables declared here are local to this if statement..
> }
> try
> SqlConnection conn;
> if(WinTrusted.checked == true)
> con = new SqlConnection("con paramas")
> else
> con = new SqlConnection("second set of param")
> }
> SqlDataAdapter myCommand = new SqlDataAdapter("sp_storedproc", myCon)
> myCommand.SelectCommand.CommandType = CommandType.StoredProc
> This should work,
> Hermit Dave
> "Norman Fritag" <mtp.net@.ozemail.com.au> wrote in message
> news:cY6Cb.10$Tq.1083@.nnrp1.ozemail.com.au...
> > Hi there
> > I what to test a stored procedures on a web page using the normal
> connection
> > string.
> > the controls: Server, username,Password, database allow to select the
> > appropriate Sql server database.
> > Now I would use checkbox = Trusted connection as option to logon to the
> > database.
> > I guess the question that I have is where am I going wrong in the code?
> > How can I step through the script before or up until the page is loaded?
> > Any hints are greatly appreciated, the same will be made available after
> > completion.
> > Regards
> > Norman
> > Here is the Code:-----------------
> > <%@. Page Language="VB" AutoEventWireup="True" %>
> > <%@. import Namespace="System.Data" %>
> > <%@. import Namespace="System.Data.SqlClient" %>
> > <%@. import Namespace="System.Web.UI.WebControls" %>
> > <HTML>
> > <HEAD>
> > <script runat="server">
> > ' code to check if the tickbox was ticked
> > Sub Check_Clicked(sender As Object, e As EventArgs)
> > If WinTrusted.checked then
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'else
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > end if
> > End Sub
> > '
> > Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
> > Dim ds As New DataSet
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";Trusted_Connection=true" & _
> > ";Initial catalog=" & Database.Text)
> > Dim cmd As New SqlCommand("sp_stored_procedures", conn) ' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > adpt.Fill(ds, "SPs")
> > SPs.DataSource = ds.Tables("SPs")
> > SPs.DataTextField = "PROCEDURE_NAME"
> > SPs.DataBind()
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > Sub GetParametersButton_Click(ByVal sender As Object, ByVal e As
> EventArgs)
> > Dim ds As New DataSet
> > 'If Wintrusted.checked = True Then
> > ' Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'Else
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";User id=" & Userid.text & _
> > ";Password=" & Password.Text & _
> > ";Initial catalog=" & Database.Text)
> > 'End If
> > Dim cmd As New SqlCommand("sp_sproc_columns", conn) '' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > cmd.CommandType = CommandType.StoredProcedure
> > cmd.Parameters.Add("@.procedure_name", SqlDbType.NVarchar, 390).Value = _
> > SPs.SelectedItem.Value
> > adpt.Fill(ds, "Parameters")
> > ParametersDataGrid.DataSource = ds.Tables("Parameters")
> > ParametersDataGrid.DataBind()
> > ResultsDataGrid.Visible = False
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > Sub AddParameters(ByVal cmd As SqlCommand)
> > 'works ok
> > End Sub
> > Sub UpdateParameters(ByVal cmd As SqlCommand)
> > 'Works Ok
> > End Sub
> > Sub ExecuteQueryButton_Click(ByVal sender As Object, ByVal e As
EventArgs)
> > Dim ds As New DataSet
> > 'If WinTrusted.checked then
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'else
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";Trusted_Connection=true" & _
> > ";Initial catalog=" & Database.Text)
> > 'end if
> > Dim cmd As New SqlCommand(SPs.SelectedItem.Value, conn) ' ' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > cmd.CommandType = CommandType.StoredProcedure
> > AddParameters(cmd)
> > adpt.Fill(ds, "Results")
> > UpdateParameters(cmd)
> > ResultsDataGrid.DataSource = ds.Tables("Results")
> > ResultsDataGrid.DataBind()
> > ResultsDataGrid.Visible = True
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > </script>
> > </HEAD>
> > ----------End of
> > Code--------------
Thanks Hermit Dave
I picked up the thought an it works Ok.
Regards

Norman

"Hermit Dave" <hermitd.REMOVE@.CAPS.AND.DOTS.hotmail.com> wrote in message
news:evdi6$DwDHA.2372@.TK2MSFTNGP09.phx.gbl...
> You problem i think is happening because you are defining the connection
in
> a if statement
> that would make it a local variable of
> if(conditional statement)
> {
> // you code and your variables.
> // any variables declared here are local to this if statement..
> }
> try
> SqlConnection conn;
> if(WinTrusted.checked == true)
> con = new SqlConnection("con paramas")
> else
> con = new SqlConnection("second set of param")
> }
> SqlDataAdapter myCommand = new SqlDataAdapter("sp_storedproc", myCon)
> myCommand.SelectCommand.CommandType = CommandType.StoredProc
> This should work,
> Hermit Dave
> "Norman Fritag" <mtp.net@.ozemail.com.au> wrote in message
> news:cY6Cb.10$Tq.1083@.nnrp1.ozemail.com.au...
> > Hi there
> > I what to test a stored procedures on a web page using the normal
> connection
> > string.
> > the controls: Server, username,Password, database allow to select the
> > appropriate Sql server database.
> > Now I would use checkbox = Trusted connection as option to logon to the
> > database.
> > I guess the question that I have is where am I going wrong in the code?
> > How can I step through the script before or up until the page is loaded?
> > Any hints are greatly appreciated, the same will be made available after
> > completion.
> > Regards
> > Norman
> > Here is the Code:-----------------
> > <%@. Page Language="VB" AutoEventWireup="True" %>
> > <%@. import Namespace="System.Data" %>
> > <%@. import Namespace="System.Data.SqlClient" %>
> > <%@. import Namespace="System.Web.UI.WebControls" %>
> > <HTML>
> > <HEAD>
> > <script runat="server">
> > ' code to check if the tickbox was ticked
> > Sub Check_Clicked(sender As Object, e As EventArgs)
> > If WinTrusted.checked then
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'else
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > end if
> > End Sub
> > '
> > Sub LoginButton_Click(ByVal sender As Object, ByVal e As EventArgs)
> > Dim ds As New DataSet
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";Trusted_Connection=true" & _
> > ";Initial catalog=" & Database.Text)
> > Dim cmd As New SqlCommand("sp_stored_procedures", conn) ' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > adpt.Fill(ds, "SPs")
> > SPs.DataSource = ds.Tables("SPs")
> > SPs.DataTextField = "PROCEDURE_NAME"
> > SPs.DataBind()
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > Sub GetParametersButton_Click(ByVal sender As Object, ByVal e As
> EventArgs)
> > Dim ds As New DataSet
> > 'If Wintrusted.checked = True Then
> > ' Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'Else
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";User id=" & Userid.text & _
> > ";Password=" & Password.Text & _
> > ";Initial catalog=" & Database.Text)
> > 'End If
> > Dim cmd As New SqlCommand("sp_sproc_columns", conn) '' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > cmd.CommandType = CommandType.StoredProcedure
> > cmd.Parameters.Add("@.procedure_name", SqlDbType.NVarchar, 390).Value = _
> > SPs.SelectedItem.Value
> > adpt.Fill(ds, "Parameters")
> > ParametersDataGrid.DataSource = ds.Tables("Parameters")
> > ParametersDataGrid.DataBind()
> > ResultsDataGrid.Visible = False
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > Sub AddParameters(ByVal cmd As SqlCommand)
> > 'works ok
> > End Sub
> > Sub UpdateParameters(ByVal cmd As SqlCommand)
> > 'Works Ok
> > End Sub
> > Sub ExecuteQueryButton_Click(ByVal sender As Object, ByVal e As
EventArgs)
> > Dim ds As New DataSet
> > 'If WinTrusted.checked then
> > 'Dim conn As New SqlConnection( _
> > ' "Data source=" & DatabaseServer.Text & _
> > ' ";Trusted_Connection=true" & _
> > ' ";Initial catalog=" & Database.Text)
> > 'else
> > Dim conn As New SqlConnection( _
> > "Data source=" & DatabaseServer.Text & _
> > ";Trusted_Connection=true" & _
> > ";Initial catalog=" & Database.Text)
> > 'end if
> > Dim cmd As New SqlCommand(SPs.SelectedItem.Value, conn) ' ' << when Sub
> > Check_Clicked and the code is run Asp courses an error at this line
saying
> > that "conn" is not defined??
> > Dim adpt As New SqlDataAdapter(cmd)
> > Try
> > Status.Text = ""
> > cmd.CommandType = CommandType.StoredProcedure
> > AddParameters(cmd)
> > adpt.Fill(ds, "Results")
> > UpdateParameters(cmd)
> > ResultsDataGrid.DataSource = ds.Tables("Results")
> > ResultsDataGrid.DataBind()
> > ResultsDataGrid.Visible = True
> > Catch ex As SqlException
> > Status.Text = ex.Message
> > End Try
> > End Sub
> > </script>
> > </HEAD>
> > ----------End of
> > Code--------------

Saturday, March 24, 2012

NEWBIE: RecordCount of SqlDataSource

Hi!

I have this SqlSataSource (aspx 2.0):

<asp:SqlDataSource ID="ArtiestenSource" Runat="server"
SelectCommand="SELECT lower(artiest) AS artiest, COUNT(DISTINCT album) AS
albums, COUNT(artiest) AS tracks, SUM(seconden) AS seconden,
CONVERT(varchar, DATEADD(second, SUM(seconden), ''), 108) AS Duur FROM
dbo.muziek GROUP BY artiest"
ConnectionString="Server=DESERVER;User
ID=sa;Password=wachtwoord;Database=Muziek;Persist Security Info=True"
ProviderName="System.Data.SqlClient">
</asp:SqlDataSource
Maybe someone knows how to retrieve the number of rows of this datasource?
(ArtiestenSource.RecordCount doesn't work. )

Also: I would display this number of rows like this:
<% response.write(ArtiestenSource.RecordCount) %
But I don't doubt there is a typical dot net 2.0 way of displaying this
result. (So, something else then <% response.write() %>.
If I am right about that, does someone know what right way is?

Thanks!

DaanYou should be able to extract the DataSet and pull the number out (would
give you code, but I do not have the 2.0 machine up and running). As far as
how to embed the number in a page, you have two choices.

1. Add a label and set the Text property
2. Use data binding <%# =variableName %> - just set the variableName in the
back and make sure it is accessible. You will have to run Page.DataBind() to
ensure it is bound, however.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"Daan" <daan@.nergens.com> wrote in message
news:cdql5b$uat$1@.news.cistron.nl...
> Hi!
> I have this SqlSataSource (aspx 2.0):
> <asp:SqlDataSource ID="ArtiestenSource" Runat="server"
> SelectCommand="SELECT lower(artiest) AS artiest, COUNT(DISTINCT album) AS
> albums, COUNT(artiest) AS tracks, SUM(seconden) AS seconden,
> CONVERT(varchar, DATEADD(second, SUM(seconden), ''), 108) AS Duur FROM
> dbo.muziek GROUP BY artiest"
> ConnectionString="Server=DESERVER;User
> ID=sa;Password=wachtwoord;Database=Muziek;Persist Security Info=True"
> ProviderName="System.Data.SqlClient">
> </asp:SqlDataSource>
> Maybe someone knows how to retrieve the number of rows of this datasource?
> (ArtiestenSource.RecordCount doesn't work. )
> Also: I would display this number of rows like this:
> <% response.write(ArtiestenSource.RecordCount) %>
> But I don't doubt there is a typical dot net 2.0 way of displaying this
> result. (So, something else then <% response.write() %>.
> If I am right about that, does someone know what right way is?
> Thanks!
> Daan
Hi!
Does anyone know how to extract the DataSet from a SqlDataSource?
(I have really been searching and trying, but I can't figger it out -> a
real newbie?)

Thanks!

Daan

"Cowboy (Gregory A. Beamer) [MVP]" <NoSpamMgbworld@.comcast.netNoSpamM>
schreef in bericht news:%231cgHrLcEHA.1656@.TK2MSFTNGP09.phx.gbl...
> You should be able to extract the DataSet and pull the number out (would
> give you code, but I do not have the 2.0 machine up and running). As far
as
> how to embed the number in a page, you have two choices.
> 1. Add a label and set the Text property
> 2. Use data binding <%# =variableName %> - just set the variableName in
the
> back and make sure it is accessible. You will have to run Page.DataBind()
to
> ensure it is bound, however.
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
> ************************************************
> Think Outside the Box!
> ************************************************
> "Daan" <daan@.nergens.com> wrote in message
> news:cdql5b$uat$1@.news.cistron.nl...
> > Hi!
> > I have this SqlSataSource (aspx 2.0):
> > <asp:SqlDataSource ID="ArtiestenSource" Runat="server"
> > SelectCommand="SELECT lower(artiest) AS artiest, COUNT(DISTINCT album)
AS
> > albums, COUNT(artiest) AS tracks, SUM(seconden) AS seconden,
> > CONVERT(varchar, DATEADD(second, SUM(seconden), ''), 108) AS Duur FROM
> > dbo.muziek GROUP BY artiest"
> > ConnectionString="Server=DESERVER;User
> > ID=sa;Password=wachtwoord;Database=Muziek;Persist Security Info=True"
> > ProviderName="System.Data.SqlClient">
> > </asp:SqlDataSource>
> > Maybe someone knows how to retrieve the number of rows of this
datasource?
> > (ArtiestenSource.RecordCount doesn't work. )
> > Also: I would display this number of rows like this:
> > <% response.write(ArtiestenSource.RecordCount) %>
> > But I don't doubt there is a typical dot net 2.0 way of displaying this
> > result. (So, something else then <% response.write() %>.
> > If I am right about that, does someone know what right way is?
> > Thanks!
> > Daan
Daan:

Here is another way to get the record count: The SqlDataSource has an event
called "Selected." It passes in a SqlDataSourceStatusEventArgs, which has a
property called "AffectedRows." I just tried hooking this event after calling
a simple select to the Products table of Northwinds and got the rowcount.

Chuck

"Daan" wrote:

> Hi!
> Does anyone know how to extract the DataSet from a SqlDataSource?
> (I have really been searching and trying, but I can't figger it out -> a
> real newbie?)
> Thanks!
> Daan
>
>
> "Cowboy (Gregory A. Beamer) [MVP]" <NoSpamMgbworld@.comcast.netNoSpamM>
> schreef in bericht news:%231cgHrLcEHA.1656@.TK2MSFTNGP09.phx.gbl...
> > You should be able to extract the DataSet and pull the number out (would
> > give you code, but I do not have the 2.0 machine up and running). As far
> as
> > how to embed the number in a page, you have two choices.
> > 1. Add a label and set the Text property
> > 2. Use data binding <%# =variableName %> - just set the variableName in
> the
> > back and make sure it is accessible. You will have to run Page.DataBind()
> to
> > ensure it is bound, however.
> > --
> > Gregory A. Beamer
> > MVP; MCP: +I, SE, SD, DBA
> > ************************************************
> > Think Outside the Box!
> > ************************************************
> > "Daan" <daan@.nergens.com> wrote in message
> > news:cdql5b$uat$1@.news.cistron.nl...
> > > Hi!
> > > > I have this SqlSataSource (aspx 2.0):
> > > > <asp:SqlDataSource ID="ArtiestenSource" Runat="server"
> > > SelectCommand="SELECT lower(artiest) AS artiest, COUNT(DISTINCT album)
> AS
> > > albums, COUNT(artiest) AS tracks, SUM(seconden) AS seconden,
> > > CONVERT(varchar, DATEADD(second, SUM(seconden), ''), 108) AS Duur FROM
> > > dbo.muziek GROUP BY artiest"
> > > ConnectionString="Server=DESERVER;User
> > > ID=sa;Password=wachtwoord;Database=Muziek;Persist Security Info=True"
> > > ProviderName="System.Data.SqlClient">
> > > </asp:SqlDataSource>
> > > > Maybe someone knows how to retrieve the number of rows of this
> datasource?
> > > (ArtiestenSource.RecordCount doesn't work. )
> > > > Also: I would display this number of rows like this:
> > > <% response.write(ArtiestenSource.RecordCount) %>
> > > > But I don't doubt there is a typical dot net 2.0 way of displaying this
> > > result. (So, something else then <% response.write() %>.
> > > If I am right about that, does someone know what right way is?
> > > > Thanks!
> > > > Daan
> > >

NEWBIE: RecordCount of SqlDataSource

Hi!
I have this SqlSataSource (aspx 2.0):
<asp:SqlDataSource ID="ArtiestenSource" Runat="server"
SelectCommand="SELECT lower(artiest) AS artiest, COUNT(DISTINCT album) AS
albums, COUNT(artiest) AS tracks, SUM(seconden) AS seconden,
CONVERT(varchar, DATEADD(second, SUM(seconden), ''), 108) AS Duur FROM
dbo.muziek GROUP BY artiest"
ConnectionString="Server=DESERVER;User
ID=sa;Password=wachtwoord;Database=Muzie
k;Persist Security Info=True"
ProviderName="System.Data.SqlClient">
</asp:SqlDataSource>
Maybe someone knows how to retrieve the number of rows of this datasource?
(ArtiestenSource.RecordCount doesn't work. )
Also: I would display this number of rows like this:
<% response.write(ArtiestenSource.RecordCount) %>
But I don't doubt there is a typical dot net 2.0 way of displaying this
result. (So, something else then <% response.write() %>.
If I am right about that, does someone know what right way is?
Thanks!
DaanYou should be able to extract the DataSet and pull the number out (would
give you code, but I do not have the 2.0 machine up and running). As far as
how to embed the number in a page, you have two choices.
1. Add a label and set the Text property
2. Use data binding <%# =variableName %> - just set the variableName in the
back and make sure it is accessible. You will have to run Page.DataBind() to
ensure it is bound, however.
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
****************************************
********
Think Outside the Box!
****************************************
********
"Daan" <daan@.nergens.com> wrote in message
news:cdql5b$uat$1@.news.cistron.nl...
> Hi!
> I have this SqlSataSource (aspx 2.0):
> <asp:SqlDataSource ID="ArtiestenSource" Runat="server"
> SelectCommand="SELECT lower(artiest) AS artiest, COUNT(DISTINCT album) AS
> albums, COUNT(artiest) AS tracks, SUM(seconden) AS seconden,
> CONVERT(varchar, DATEADD(second, SUM(seconden), ''), 108) AS Duur FROM
> dbo.muziek GROUP BY artiest"
> ConnectionString="Server=DESERVER;User
> ID=sa;Password=wachtwoord;Database=Muzie
k;Persist Security Info=True"
> ProviderName="System.Data.SqlClient">
> </asp:SqlDataSource>
> Maybe someone knows how to retrieve the number of rows of this datasource?
> (ArtiestenSource.RecordCount doesn't work. )
> Also: I would display this number of rows like this:
> <% response.write(ArtiestenSource.RecordCount) %>
> But I don't doubt there is a typical dot net 2.0 way of displaying this
> result. (So, something else then <% response.write() %>.
> If I am right about that, does someone know what right way is?
> Thanks!
> Daan
>
Hi!
Does anyone know how to extract the DataSet from a SqlDataSource?
(I have really been searching and trying, but I can't figger it out -> a
real newbie?)
Thanks!
Daan
"Cowboy (Gregory A. Beamer) [MVP]" <NoSpamMgbworld@.comcast.netNoSpamM>
schreef in bericht news:%231cgHrLcEHA.1656@.TK2MSFTNGP09.phx.gbl...
> You should be able to extract the DataSet and pull the number out (would
> give you code, but I do not have the 2.0 machine up and running). As far
as
> how to embed the number in a page, you have two choices.
> 1. Add a label and set the Text property
> 2. Use data binding <%# =variableName %> - just set the variableName in
the
> back and make sure it is accessible. You will have to run Page.DataBind()
to
> ensure it is bound, however.
> --
> Gregory A. Beamer
> MVP; MCP: +I, SE, SD, DBA
> ****************************************
********
> Think Outside the Box!
> ****************************************
********
> "Daan" <daan@.nergens.com> wrote in message
> news:cdql5b$uat$1@.news.cistron.nl...
AS
datasource?
>
Daan:
Here is another way to get the record count: The SqlDataSource has an event
called "Selected." It passes in a SqlDataSourceStatusEventArgs, which has a
property called "AffectedRows." I just tried hooking this event after callin
g
a simple select to the Products table of Northwinds and got the rowcount.
Chuck
"Daan" wrote:

> Hi!
> Does anyone know how to extract the DataSet from a SqlDataSource?
> (I have really been searching and trying, but I can't figger it out -> a
> real newbie?)
> Thanks!
> Daan
>
>
> "Cowboy (Gregory A. Beamer) [MVP]" <NoSpamMgbworld@.comcast.netNoSpamM>
> schreef in bericht news:%231cgHrLcEHA.1656@.TK2MSFTNGP09.phx.gbl...
> as
> the
> to
> AS
> datasource?
>
>

Newbie: Upload large file from client to server in ASP.NET

I have seen many posts for this same subject, but my project has some
odd requirements. I need to develop an ASP app that will upload a
large file (200 MB+) to a server without any user interaction, meaning
I can's simply put a file input box on the page and let the user
choose the file. I basically need them to click a button and have the
file transferred. I know that this would be a dangerous practice if
anyone could do it, but is it possible in a controlled environment?
Because of the size of the file I have been looking at FTPing it, but
can't figure out how to get client script to start the FTP. I have
also found this code (below) that utilizes a web service, but I don't
see how the client-script would get the file from the client since it
appears to be ASP. Any ideas for this situation would be MUCH
appreciated.

<WebMethod()> PublicFunction UploadFile(ByVal fs()AsByte,ByVal
FlNameAsString)AsString
Try
Dim m As New MemoryStream(fs)
Dim f As New FileStream("c:\tempUploaded\" & FlName,
FileMode.Create)
m.WriteTo(f)
m.Close()
f.Close()
f = Nothing
m = Nothing
Return "File Uploaded"

Catch ex As Exception
Return ex.Message
End Try
End Function

The UploadFile Webmethod accepts a byte array and the name of the
file, the byte array is copied to a memory stream which is written to
a FileStream.

The client code to upload a file,

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Try
Dim f As System.IO.File
Dim fs As System.IO.FileStream
Dim o As New localhost.Service1()
'file to upload
fs = f.Open("c:\upload.pdf", IO.FileMode.Open, IO.FileAccess.Read)
Dim b(fs.Length - 1) As Byte
fs.Read(b, 0, fs.Length)
MsgBox(o.UploadFile(b, "upload.pdf"))
f = Nothing
fs.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End SubYou can use the HTTP classes to write an upload client as a Winexe, there
are examples in the SDK of how to do this using the webclient uploadfile
method, as shown here.

Console.Write("\nPlease enter the URL to post data to : ");
String uriString = Console.ReadLine();

// Create a new WebClient instance.
WebClient myWebClient = new WebClient();

Console.WriteLine("\nPlease enter the fully qualified path of the
file to be uploaded to the URL");
string fileName = Console.ReadLine();

Console.WriteLine("Uploading {0} to {1} ...",fileName,uriString);
// Upload the file to the URL using the HTTP 1.0 POST.
byte[] responseArray =
myWebClient.UploadFile(uriString,"POST",fileName);

// Decode and display the response.
Console.WriteLine("\nResponse Received.The contents of the file
uploaded are: \n{0}",Encoding.ASCII.GetString(responseArray));

You then need to control your server side timouts, and set your
machine.config settings to control the ma file size permitted for uplaods
(look it up - cant recall all the settings)

If you want to resort to FTP, then you can easily script the FTP.EXE that
comes with windows with the /s flag.

--
Regards

John Timney (Microsoft ASP.NET MVP)
--------------
<shameless_author_plug>
Professional .NET for Java Developers with C#
ISBN:1-861007-91-4
Professional Windows Forms
ISBN: 1861005547
Professional JSP 2nd Edition
ISBN: 1861004958
Professional JSP
ISBN: 1861003625
Beginning JSP Web Development
ISBN: 1861002092
</shameless_author_plug>
--------------

"Greg" <greg_leflar@.hotmail.com> wrote in message
news:1651b2f9.0308171354.6c1ee8ae@.posting.google.c om...
> I have seen many posts for this same subject, but my project has some
> odd requirements. I need to develop an ASP app that will upload a
> large file (200 MB+) to a server without any user interaction, meaning
> I can's simply put a file input box on the page and let the user
> choose the file. I basically need them to click a button and have the
> file transferred. I know that this would be a dangerous practice if
> anyone could do it, but is it possible in a controlled environment?
> Because of the size of the file I have been looking at FTPing it, but
> can't figure out how to get client script to start the FTP. I have
> also found this code (below) that utilizes a web service, but I don't
> see how the client-script would get the file from the client since it
> appears to be ASP. Any ideas for this situation would be MUCH
> appreciated.
> <WebMethod()> PublicFunction UploadFile(ByVal fs()AsByte,ByVal
> FlNameAsString)AsString
> Try
> Dim m As New MemoryStream(fs)
> Dim f As New FileStream("c:\tempUploaded\" & FlName,
> FileMode.Create)
> m.WriteTo(f)
> m.Close()
> f.Close()
> f = Nothing
> m = Nothing
> Return "File Uploaded"
> Catch ex As Exception
> Return ex.Message
> End Try
> End Function
> The UploadFile Webmethod accepts a byte array and the name of the
> file, the byte array is copied to a memory stream which is written to
> a FileStream.
> The client code to upload a file,
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> Try
> Dim f As System.IO.File
> Dim fs As System.IO.FileStream
> Dim o As New localhost.Service1()
> 'file to upload
> fs = f.Open("c:\upload.pdf", IO.FileMode.Open, IO.FileAccess.Read)
> Dim b(fs.Length - 1) As Byte
> fs.Read(b, 0, fs.Length)
> MsgBox(o.UploadFile(b, "upload.pdf"))
> f = Nothing
> fs.Close()
> Catch ex As Exception
> MsgBox(ex.Message)
> End Try
> End Sub
Thank you for your reply. Your code sample makes sense. How would I
then execute that script on the client from an aspx? Again, I don't
know if this is even possible because of the devious implications, but
the client is on our LAN so I have complete control.

"John Timney \(Microsoft MVP\)" <timneyj@.despammed.com> wrote in message news:<OT1XywQZDHA.2668@.TK2MSFTNGP09.phx.gbl>...
> You can use the HTTP classes to write an upload client as a Winexe, there
> are examples in the SDK of how to do this using the webclient uploadfile
> method, as shown here.
> Console.Write("\nPlease enter the URL to post data to : ");
> String uriString = Console.ReadLine();
> // Create a new WebClient instance.
> WebClient myWebClient = new WebClient();
> Console.WriteLine("\nPlease enter the fully qualified path of the
> file to be uploaded to the URL");
> string fileName = Console.ReadLine();
> Console.WriteLine("Uploading {0} to {1} ...",fileName,uriString);
> // Upload the file to the URL using the HTTP 1.0 POST.
> byte[] responseArray =
> myWebClient.UploadFile(uriString,"POST",fileName);
> // Decode and display the response.
> Console.WriteLine("\nResponse Received.The contents of the file
> uploaded are: \n{0}",Encoding.ASCII.GetString(responseArray));
> You then need to control your server side timouts, and set your
> machine.config settings to control the ma file size permitted for uplaods
> (look it up - cant recall all the settings)
> If you want to resort to FTP, then you can easily script the FTP.EXE that
> comes with windows with the /s flag.
> --
> Regards
> John Timney (Microsoft ASP.NET MVP)
> --------------
> <shameless_author_plug>
> Professional .NET for Java Developers with C#
> ISBN:1-861007-91-4
> Professional Windows Forms
> ISBN: 1861005547
> Professional JSP 2nd Edition
> ISBN: 1861004958
> Professional JSP
> ISBN: 1861003625
> Beginning JSP Web Development
> ISBN: 1861002092
> </shameless_author_plug>
> --------------
> "Greg" <greg_leflar@.hotmail.com> wrote in message
> news:1651b2f9.0308171354.6c1ee8ae@.posting.google.c om...
> > I have seen many posts for this same subject, but my project has some
> > odd requirements. I need to develop an ASP app that will upload a
> > large file (200 MB+) to a server without any user interaction, meaning
> > I can's simply put a file input box on the page and let the user
> > choose the file. I basically need them to click a button and have the
> > file transferred. I know that this would be a dangerous practice if
> > anyone could do it, but is it possible in a controlled environment?
> > Because of the size of the file I have been looking at FTPing it, but
> > can't figure out how to get client script to start the FTP. I have
> > also found this code (below) that utilizes a web service, but I don't
> > see how the client-script would get the file from the client since it
> > appears to be ASP. Any ideas for this situation would be MUCH
> > appreciated.
> > <WebMethod()> PublicFunction UploadFile(ByVal fs()AsByte,ByVal
> > FlNameAsString)AsString
> > Try
> > Dim m As New MemoryStream(fs)
> > Dim f As New FileStream("c:\tempUploaded\" & FlName,
> > FileMode.Create)
> > m.WriteTo(f)
> > m.Close()
> > f.Close()
> > f = Nothing
> > m = Nothing
> > Return "File Uploaded"
> > Catch ex As Exception
> > Return ex.Message
> > End Try
> > End Function
> > The UploadFile Webmethod accepts a byte array and the name of the
> > file, the byte array is copied to a memory stream which is written to
> > a FileStream.
> > The client code to upload a file,
> > Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> > System.EventArgs) Handles Button1.Click
> > Try
> > Dim f As System.IO.File
> > Dim fs As System.IO.FileStream
> > Dim o As New localhost.Service1()
> > 'file to upload
> > fs = f.Open("c:\upload.pdf", IO.FileMode.Open, IO.FileAccess.Read)
> > Dim b(fs.Length - 1) As Byte
> > fs.Read(b, 0, fs.Length)
> > MsgBox(o.UploadFile(b, "upload.pdf"))
> > f = Nothing
> > fs.Close()
> > Catch ex As Exception
> > MsgBox(ex.Message)
> > End Try
> > End Sub

Friday, March 16, 2012

Newsgroup Web Interface

I have a newsgroup set up on my web server. How to I
develop an web interace to use on an .asp page so users
can view / post the newsgroup via the web?

I cannot find any how-to's on this.

Daryl Grantham
Knoxville, TNHi Daryl,

There are some projects here that might give you some ideas on the protocols
and techniques:

http://sourceforge.net/projects/dougnewsnntp/
http://sourceforge.net/projects/phnntp/
http://sourceforge.net/projects/netclientsnet/

"d_grantham" <grant742@.bellsouth.net> wrote in message
news:023001c3c705$469268f0$a001280a@.phx.gbl...
>I have a newsgroup set up on my web server. How to I
> develop an web interace to use on an .asp page so users
> can view / post the newsgroup via the web?
> I cannot find any how-to's on this.
>
> Daryl Grantham
> Knoxville, TN