Showing posts with label sql. Show all posts
Showing posts with label sql. Show all posts

Thursday, March 29, 2012

newbie: how do I? <export table to sql script>

Hey

I've created a simple asp.net 2.0 (visual studio 2005) project containing a
database in the App_Data folder

I wonder how I can export individual tables from this database to sql
script...

Any suggestions?

JeffOkay, I've sold this by using Sql Express 2005 Managment Tool

"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:%23EHhcDF%23GHA.4696@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

Hey
>
I've created a simple asp.net 2.0 (visual studio 2005) project containing
a database in the App_Data folder
>
I wonder how I can export individual tables from this database to sql
script...
>
Any suggestions?
>
Jeff
>


I mean solved it... :-)

"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:%23TnApCG%23GHA.748@.TK2MSFTNGP02.phx.gbl...

Quote:

Originally Posted by

Okay, I've sold this by using Sql Express 2005 Managment Tool
>
"Jeff" <it_consultant1@.hotmail.com.NOSPAMwrote in message
news:%23EHhcDF%23GHA.4696@.TK2MSFTNGP05.phx.gbl...

Quote:

Originally Posted by

>Hey
>>
>I've created a simple asp.net 2.0 (visual studio 2005) project containing
>a database in the App_Data folder
>>
>I wonder how I can export individual tables from this database to sql
>script...
>>
>Any suggestions?
>>
>Jeff
>>


>
>

newbie: how do I? <export table to sql script>

Hey
I've created a simple asp.net 2.0 (visual studio 2005) project containing a
database in the App_Data folder
I wonder how I can export individual tables from this database to sql
script...
Any suggestions?
JeffOkay, I've sold this by using Sql Express 2005 Managment Tool
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:%23EHhcDF%23GHA.4696@.TK2MSFTNGP05.phx.gbl...
> Hey
> I've created a simple asp.net 2.0 (visual studio 2005) project containing
> a database in the App_Data folder
> I wonder how I can export individual tables from this database to sql
> script...
> Any suggestions?
> Jeff
>
I mean solved it... :-)
"Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
news:%23TnApCG%23GHA.748@.TK2MSFTNGP02.phx.gbl...
> Okay, I've sold this by using Sql Express 2005 Managment Tool
> "Jeff" <it_consultant1@.hotmail.com.NOSPAM> wrote in message
> news:%23EHhcDF%23GHA.4696@.TK2MSFTNGP05.phx.gbl...
>

newbie: how to compare bit field from sql table to oledbdatareader?

Hi, I made a bit field off my sql table to represent true/false.
I'm having trouble to use compare the value off that table using OleDbDataReader, please help correct my code:
string connectionString = "(connect goes here)";
string sql = "SELECT isActived FROM List WHERE ID=@dotnet.itags.org.ID";
SqlConnection conn = new SqlConnection(connectionString);
SqlDataReader reader = null;
conn.Open();
SqlCommand cmd = new SqlCommand(sql,conn);
cmd.Parameters.Add("@dotnet.itags.org.license", "(my id number goes here)");
reader = cmd.ExecuteReader();
(something wrong with this code:) bool temp = reader["isActived"];
(or this:) if (
reader["isActived"] == true)
reader.Close();
conn.Close();
TIA

After a call to ExecuteRead, the reader is positioned before the first row. You must call reader.Read() to position the reader on a row before you attempt to access any data.


If you only get one value back, you may try this:
bool temp = cmd.ExecuteScalar();


thanks DMW, Jimmy, looks like ExecuteScalar would help me save a couple lines of 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.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:
>

Thursday, March 22, 2012

Newby question

Hi

I need help at the very beginning. I have been writing classic ASP for some
time, but getting data out of a SQL database and displaying a single value
eludes me.

So far I have the following code:

Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
Source=SQLServer;Initial Catalog=database;")
Dim myCommand As New SqlDataAdapter("select Name from Products where code =
0117", myConnection)

Dim ds As New DataSet()
myCommand.Fill(ds, "Name")

to get a record out of the database. All I want to do now put the Name in
that record into a variable and use it in the HTML text. I would appreciate
any help.

Thank you
HermannFirst off, the Fill method is a method of the SqlDataAdapter class so to use
Fill, you'd have to create a data adapter first, but you don't need a
dataset for what you're doing. Use the ExecuteScalar() method of the
SqlCommand class to return a single value. Search the framework
documentation for "Obtaining a Single Value from a Database".

In order to use that server side variable in your HTML, do it just as you
would in classic ASP:

<p>Product name for product code 0117 is: <%= myVariable %>.</p
Dale

"Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
> Hi
> I need help at the very beginning. I have been writing classic ASP for
some
> time, but getting data out of a SQL database and displaying a single value
> eludes me.
> So far I have the following code:
> Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
> Source=SQLServer;Initial Catalog=database;")
> Dim myCommand As New SqlDataAdapter("select Name from Products where code
=
> 0117", myConnection)
> Dim ds As New DataSet()
> myCommand.Fill(ds, "Name")
> to get a record out of the database. All I want to do now put the Name in
> that record into a variable and use it in the HTML text. I would
appreciate
> any help.
> Thank you
> Hermann
Hello Hermann,

An dataset is probably complete overkill for what you're trying to accomplish here.

Try this:

(c# code, but VB should be pretty similar)
SqlConnection myConnection = new SqlConnection("UID=dbuser;PWD=thepass;Data Source=server;Initial Catalog=database;");
SqlCommand cmd = new SqlCommand("select name from products where code = 0117", myConnection);

string s = (string)cmd.ExecuteScalar();

ExecuteScalar will receive one value from a database. It is up to you to cast it to the appropriate type.

HTH,

--
Matt Berther
http://www.mattberther.com
Hello DalePres,

Dale, in his code example, he was creating a SqlDataAdapter. The variable name was just wrong. ;)

> First off, the Fill method is a method of the SqlDataAdapter class so
> to use Fill, you'd have to create a data adapter first, but you don't
> need a dataset for what you're doing. Use the ExecuteScalar() method
> of the SqlCommand class to return a single value. Search the
> framework documentation for "Obtaining a Single Value from a
> Database".
> In order to use that server side variable in your HTML, do it just as
> you would in classic ASP:
> <p>Product name for product code 0117 is: <%= myVariable %>.</p>
> Dale
> "Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
> news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
>> Hi
>>
>> I need help at the very beginning. I have been writing classic ASP
>> for
>>
> some
>> time, but getting data out of a SQL database and displaying a single
>> value eludes me.
>>
>> So far I have the following code:
>>
>> Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
>> Source=SQLServer;Initial Catalog=database;")
>> Dim myCommand As New SqlDataAdapter("select Name from Products where
>> code
> =
>> 0117", myConnection)
>>
>> Dim ds As New DataSet()
>> myCommand.Fill(ds, "Name")
>> to get a record out of the database. All I want to do now put the
>> Name in that record into a variable and use it in the HTML text. I
>> would
>>
> appreciate
>> any help.
>>
>> Thank you
>> Hermann
--

--
Matt Berther
http://www.mattberther.com
You're right. I didn't catch that one at all. I guess that's why variable
naming is so important.

Dale

"Matt Berther" <mberther@.hotmail.com> wrote in message
news:OQF5$FAMEHA.140@.TK2MSFTNGP09.phx.gbl...
> Hello DalePres,
> Dale, in his code example, he was creating a SqlDataAdapter. The variable
name was just wrong. ;)
> > First off, the Fill method is a method of the SqlDataAdapter class so
> > to use Fill, you'd have to create a data adapter first, but you don't
> > need a dataset for what you're doing. Use the ExecuteScalar() method
> > of the SqlCommand class to return a single value. Search the
> > framework documentation for "Obtaining a Single Value from a
> > Database".
> > In order to use that server side variable in your HTML, do it just as
> > you would in classic ASP:
> > <p>Product name for product code 0117 is: <%= myVariable %>.</p>
> > Dale
> > "Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
> > news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
> >> Hi
> >>
> >> I need help at the very beginning. I have been writing classic ASP
> >> for
> >>
> > some
> >> time, but getting data out of a SQL database and displaying a single
> >> value eludes me.
> >>
> >> So far I have the following code:
> >>
> >> Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
> >> Source=SQLServer;Initial Catalog=database;")
> >> Dim myCommand As New SqlDataAdapter("select Name from Products where
> >> code
> > =
> >> 0117", myConnection)
> >>
> >> Dim ds As New DataSet()
> >> myCommand.Fill(ds, "Name")
> >> to get a record out of the database. All I want to do now put the
> >> Name in that record into a variable and use it in the HTML text. I
> >> would
> >>
> > appreciate
> >> any help.
> >>
> >> Thank you
> >> Hermann
> --
> --
> Matt Berther
> http://www.mattberther.com
You should look at the Microsoft Data Access Application Block. This
simplifies the process a great deal. In any case, whether you use the
application block or not, if you just want one value, you can use the
ExecuteScalar method of the SQLCommand class to readily return it, or the
equivalent method of the SQLHelper class defined in the Data Access
Application Block.

Take a look at
http://www.microsoft.com/resources/...diences.asp#dev

Scroll down a ways, and you'll find a link to the Data Access Application
Block, as well as a wealth of other useful information.

"Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
> Hi
> I need help at the very beginning. I have been writing classic ASP for
some
> time, but getting data out of a SQL database and displaying a single value
> eludes me.
> So far I have the following code:
> Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
> Source=SQLServer;Initial Catalog=database;")
> Dim myCommand As New SqlDataAdapter("select Name from Products where code
=
> 0117", myConnection)
> Dim ds As New DataSet()
> myCommand.Fill(ds, "Name")
> to get a record out of the database. All I want to do now put the Name in
> that record into a variable and use it in the HTML text. I would
appreciate
> any help.
> Thank you
> Hermann
Hi

Thanks for your help. The code example comes straight out of a tutorial on
asp.net!

Unfortunately, I do not at this time have the leisure to learn the ins and
outs of the .net methods. All I need is the equivalent code to:

Set Connect = Server.CreateObject("ADODB.Connection")
Connect.Open "dbname","username","password"

Query = "Select * from links Where ID = '" & id & "'"
Set RS = Connect.Execute(Query) <-- I thought this is the dataset

code = RS("code")
title = RS("title")
url = RS("url")
email = RS("email")
description = RS("description")
retlink = RS("retlink")

I would be very thankful if someone could help me write a the code to do the
same thing under .net.

Thanks
Hermann

"Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
> Hi
> I need help at the very beginning. I have been writing classic ASP for
some
> time, but getting data out of a SQL database and displaying a single value
> eludes me.
> So far I have the following code:
> Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
> Source=SQLServer;Initial Catalog=database;")
> Dim myCommand As New SqlDataAdapter("select Name from Products where code
=
> 0117", myConnection)
> Dim ds As New DataSet()
> myCommand.Fill(ds, "Name")
> to get a record out of the database. All I want to do now put the Name in
> that record into a variable and use it in the HTML text. I would
appreciate
> any help.
> Thank you
> Hermann
Hello Hermann,

SqlConnection myConnection = new SqlConnection("UID=dbuser;PWD=thepass;Data Source=server;Initial Catalog=database;");

SqlCommand cmd = new SqlCommand("select name from products where code = 0117", myConnection);

using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection) )
{
rdr.Read(); // if you want to loop through records, sorround this with a while block

string code = rdr["code"].ToString();
string title = rdr["title"].ToString();
string url = rdr["url"].ToString();
string email = rdr["email"].ToString();
string description = rdr["description"].ToString();
string retlink = rdr["retlink"].ToString();
}

> Hi
> Thanks for your help. The code example comes straight out of a
> tutorial on asp.net!
> Unfortunately, I do not at this time have the leisure to learn the ins
> and outs of the .net methods. All I need is the equivalent code to:
> Set Connect = Server.CreateObject("ADODB.Connection")
> Connect.Open "dbname","username","password"
> Query = "Select * from links Where ID = '" & id & "'"
> Set RS = Connect.Execute(Query) <-- I thought this is the dataset
> code = RS("code")
> title = RS("title")
> url = RS("url")
> email = RS("email")
> description = RS("description")
> retlink = RS("retlink")
> I would be very thankful if someone could help me write a the code to
> do the same thing under .net.
> Thanks
> Hermann
> "Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
> news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
>> Hi
>>
>> I need help at the very beginning. I have been writing classic ASP
>> for
>>
> some
>> time, but getting data out of a SQL database and displaying a single
>> value eludes me.
>>
>> So far I have the following code:
>>
>> Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
>> Source=SQLServer;Initial Catalog=database;")
>> Dim myCommand As New SqlDataAdapter("select Name from Products where
>> code
> =
>> 0117", myConnection)
>>
>> Dim ds As New DataSet()
>> myCommand.Fill(ds, "Name")
>> to get a record out of the database. All I want to do now put the
>> Name in that record into a variable and use it in the HTML text. I
>> would
>>
> appreciate
>> any help.
>>
>> Thank you
>> Hermann
--

--
Matt Berther
http://www.mattberther.com
Hi
Much Thanks for the code. I placed on a test page with the correct
variables, but received this error message:

Compiler Error Message: BC30684: 'SqlConnection' is a type and cannot be
used as an expression

I have the following lines at the top of the page:

<%@. import Namespace="System.Data" %>
<%@. import Namespace="System.Data.SqlClient" %
Do I need to add anything else?
Thanks again
Hermann

"Matt Berther" <mberther@.hotmail.com> wrote in message
news:ONNBoITMEHA.2532@.TK2MSFTNGP10.phx.gbl...
> Hello Hermann,
> SqlConnection myConnection = new
SqlConnection("UID=dbuser;PWD=thepass;Data Source=server;Initial
Catalog=database;");
> SqlCommand cmd = new SqlCommand("select name from products where code =
0117", myConnection);
> using (IDataReader rdr =
cmd.ExecuteReader(CommandBehavior.CloseConnection) )
> {
> rdr.Read(); // if you want to loop through records, sorround this with
a while block
> string code = rdr["code"].ToString();
> string title = rdr["title"].ToString();
> string url = rdr["url"].ToString();
> string email = rdr["email"].ToString();
> string description = rdr["description"].ToString();
> string retlink = rdr["retlink"].ToString();
> }
> > Hi
> > Thanks for your help. The code example comes straight out of a
> > tutorial on asp.net!
> > Unfortunately, I do not at this time have the leisure to learn the ins
> > and outs of the .net methods. All I need is the equivalent code to:
> > Set Connect = Server.CreateObject("ADODB.Connection")
> > Connect.Open "dbname","username","password"
> > Query = "Select * from links Where ID = '" & id & "'"
> > Set RS = Connect.Execute(Query) <-- I thought this is the dataset
> > code = RS("code")
> > title = RS("title")
> > url = RS("url")
> > email = RS("email")
> > description = RS("description")
> > retlink = RS("retlink")
> > I would be very thankful if someone could help me write a the code to
> > do the same thing under .net.
> > Thanks
> > Hermann
> > "Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
> > news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
> >> Hi
> >>
> >> I need help at the very beginning. I have been writing classic ASP
> >> for
> >>
> > some
> >> time, but getting data out of a SQL database and displaying a single
> >> value eludes me.
> >>
> >> So far I have the following code:
> >>
> >> Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
> >> Source=SQLServer;Initial Catalog=database;")
> >> Dim myCommand As New SqlDataAdapter("select Name from Products where
> >> code
> > =
> >> 0117", myConnection)
> >>
> >> Dim ds As New DataSet()
> >> myCommand.Fill(ds, "Name")
> >> to get a record out of the database. All I want to do now put the
> >> Name in that record into a variable and use it in the HTML text. I
> >> would
> >>
> > appreciate
> >> any help.
> >>
> >> Thank you
> >> Hermann
> --
> --
> Matt Berther
> http://www.mattberther.com
Hello Hermann,

Try putting this in the .cs code-behind file in Page_Load.

> Hi
> Much Thanks for the code. I placed on a test page with the correct
> variables, but received this error message:
> Compiler Error Message: BC30684: 'SqlConnection' is a type and cannot
> be used as an expression
> I have the following lines at the top of the page:
> <%@. import Namespace="System.Data" %>
> <%@. import Namespace="System.Data.SqlClient" %>
> Do I need to add anything else?
> Thanks again
> Hermann
> "Matt Berther" <mberther@.hotmail.com> wrote in message
> news:ONNBoITMEHA.2532@.TK2MSFTNGP10.phx.gbl...
>> Hello Hermann,
>>
>> SqlConnection myConnection = new
>>
> SqlConnection("UID=dbuser;PWD=thepass;Data Source=server;Initial
> Catalog=database;");
>> SqlCommand cmd = new SqlCommand("select name from products where code
>> =
>>
> 0117", myConnection);
>> using (IDataReader rdr =
>>
> cmd.ExecuteReader(CommandBehavior.CloseConnection) )
>> {
>> rdr.Read(); // if you want to loop through records, sorround this
>> with
> a while block
>> string code = rdr["code"].ToString();
>> string title = rdr["title"].ToString();
>> string url = rdr["url"].ToString();
>> string email = rdr["email"].ToString();
>> string description = rdr["description"].ToString();
>> string retlink = rdr["retlink"].ToString();
>> }
>>> Hi
>>>
>>> Thanks for your help. The code example comes straight out of a
>>> tutorial on asp.net!
>>>
>>> Unfortunately, I do not at this time have the leisure to learn the
>>> ins and outs of the .net methods. All I need is the equivalent code
>>> to:
>>>
>>> Set Connect = Server.CreateObject("ADODB.Connection")
>>> Connect.Open "dbname","username","password"
>>> Query = "Select * from links Where ID = '" & id & "'"
>>> Set RS = Connect.Execute(Query) <-- I thought this is the dataset
>>> code = RS("code")
>>> title = RS("title")
>>> url = RS("url")
>>> email = RS("email")
>>> description = RS("description")
>>> retlink = RS("retlink")
>>> I would be very thankful if someone could help me write a the code
>>> to
>>> do the same thing under .net.
>>> Thanks
>>> Hermann
>>> "Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
>>> news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
>>>> Hi
>>>>
>>>> I need help at the very beginning. I have been writing classic ASP
>>>> for
>>>>
>>> some
>>>
>>>> time, but getting data out of a SQL database and displaying a
>>>> single value eludes me.
>>>>
>>>> So far I have the following code:
>>>>
>>>> Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
>>>> Source=SQLServer;Initial Catalog=database;")
>>>> Dim myCommand As New SqlDataAdapter("select Name from Products
>>>> where
>>>> code
>>> =
>>>
>>>> 0117", myConnection)
>>>>
>>>> Dim ds As New DataSet()
>>>> myCommand.Fill(ds, "Name")
>>>> to get a record out of the database. All I want to do now put the
>>>> Name in that record into a variable and use it in the HTML text. I
>>>> would
>>> appreciate
>>>
>>>> any help.
>>>>
>>>> Thank you
>>>> Hermann
>> --
>>
>> --
>> Matt Berther
>> http://www.mattberther.com
--

--
Matt Berther
http://www.mattberther.com
Hi

Can you explain what you mean with "Page_Load"?
Thanks
Hermann

"Matt Berther" <mberther@.hotmail.com> wrote in message
news:%23C6uZOaMEHA.644@.tk2msftngp13.phx.gbl...
> Hello Hermann,
> Try putting this in the .cs code-behind file in Page_Load.
> > Hi
> > Much Thanks for the code. I placed on a test page with the correct
> > variables, but received this error message:
> > Compiler Error Message: BC30684: 'SqlConnection' is a type and cannot
> > be used as an expression
> > I have the following lines at the top of the page:
> > <%@. import Namespace="System.Data" %>
> > <%@. import Namespace="System.Data.SqlClient" %>
> > Do I need to add anything else?
> > Thanks again
> > Hermann
> > "Matt Berther" <mberther@.hotmail.com> wrote in message
> > news:ONNBoITMEHA.2532@.TK2MSFTNGP10.phx.gbl...
> >> Hello Hermann,
> >>
> >> SqlConnection myConnection = new
> >>
> > SqlConnection("UID=dbuser;PWD=thepass;Data Source=server;Initial
> > Catalog=database;");
> >> SqlCommand cmd = new SqlCommand("select name from products where code
> >> =
> >>
> > 0117", myConnection);
> >> using (IDataReader rdr =
> >>
> > cmd.ExecuteReader(CommandBehavior.CloseConnection) )
> >> {
> >> rdr.Read(); // if you want to loop through records, sorround this
> >> with
> > a while block
> >> string code = rdr["code"].ToString();
> >> string title = rdr["title"].ToString();
> >> string url = rdr["url"].ToString();
> >> string email = rdr["email"].ToString();
> >> string description = rdr["description"].ToString();
> >> string retlink = rdr["retlink"].ToString();
> >> }
> >>> Hi
> >>>
> >>> Thanks for your help. The code example comes straight out of a
> >>> tutorial on asp.net!
> >>>
> >>> Unfortunately, I do not at this time have the leisure to learn the
> >>> ins and outs of the .net methods. All I need is the equivalent code
> >>> to:
> >>>
> >>> Set Connect = Server.CreateObject("ADODB.Connection")
> >>> Connect.Open "dbname","username","password"
> >>> Query = "Select * from links Where ID = '" & id & "'"
> >>> Set RS = Connect.Execute(Query) <-- I thought this is the dataset
> >>> code = RS("code")
> >>> title = RS("title")
> >>> url = RS("url")
> >>> email = RS("email")
> >>> description = RS("description")
> >>> retlink = RS("retlink")
> >>> I would be very thankful if someone could help me write a the code
> >>> to
> >>> do the same thing under .net.
> >>> Thanks
> >>> Hermann
> >>> "Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
> >>> news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
> >>>> Hi
> >>>>
> >>>> I need help at the very beginning. I have been writing classic ASP
> >>>> for
> >>>>
> >>> some
> >>>
> >>>> time, but getting data out of a SQL database and displaying a
> >>>> single value eludes me.
> >>>>
> >>>> So far I have the following code:
> >>>>
> >>>> Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
> >>>> Source=SQLServer;Initial Catalog=database;")
> >>>> Dim myCommand As New SqlDataAdapter("select Name from Products
> >>>> where
> >>>> code
> >>> =
> >>>
> >>>> 0117", myConnection)
> >>>>
> >>>> Dim ds As New DataSet()
> >>>> myCommand.Fill(ds, "Name")
> >>>> to get a record out of the database. All I want to do now put the
> >>>> Name in that record into a variable and use it in the HTML text. I
> >>>> would
> >>> appreciate
> >>>
> >>>> any help.
> >>>>
> >>>> Thank you
> >>>> Hermann
> >> --
> >>
> >> --
> >> Matt Berther
> >> http://www.mattberther.com
> --
> --
> Matt Berther
> http://www.mattberther.com
there is a Page_Load event, which you can implement. I believe he wants you
to put the code he provided into that event handler.

private void Page_Load (object sender, System.EventArgs e)
{
// your code here
}

this is part of the 'code behind' technology in ASP.net.

hope that helps,
sincerely,
J

"Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
news:eQCc71jMEHA.3972@.TK2MSFTNGP10.phx.gbl...
> Hi
> Can you explain what you mean with "Page_Load"?
> Thanks
> Hermann
> "Matt Berther" <mberther@.hotmail.com> wrote in message
> news:%23C6uZOaMEHA.644@.tk2msftngp13.phx.gbl...
> > Hello Hermann,
> > Try putting this in the .cs code-behind file in Page_Load.
> > > Hi
> > > Much Thanks for the code. I placed on a test page with the correct
> > > variables, but received this error message:
> > > Compiler Error Message: BC30684: 'SqlConnection' is a type and cannot
> > > be used as an expression
> > > > I have the following lines at the top of the page:
> > > > <%@. import Namespace="System.Data" %>
> > > <%@. import Namespace="System.Data.SqlClient" %>
> > > Do I need to add anything else?
> > > Thanks again
> > > Hermann
> > > "Matt Berther" <mberther@.hotmail.com> wrote in message
> > > news:ONNBoITMEHA.2532@.TK2MSFTNGP10.phx.gbl...
> > > >> Hello Hermann,
> > >>
> > >> SqlConnection myConnection = new
> > >>
> > > SqlConnection("UID=dbuser;PWD=thepass;Data Source=server;Initial
> > > Catalog=database;");
> > > >> SqlCommand cmd = new SqlCommand("select name from products where code
> > >> =
> > >>
> > > 0117", myConnection);
> > > >> using (IDataReader rdr =
> > >>
> > > cmd.ExecuteReader(CommandBehavior.CloseConnection) )
> > > >> {
> > >> rdr.Read(); // if you want to loop through records, sorround this
> > >> with
> > > a while block
> > > >> string code = rdr["code"].ToString();
> > >> string title = rdr["title"].ToString();
> > >> string url = rdr["url"].ToString();
> > >> string email = rdr["email"].ToString();
> > >> string description = rdr["description"].ToString();
> > >> string retlink = rdr["retlink"].ToString();
> > >> }
> > >>> Hi
> > >>>
> > >>> Thanks for your help. The code example comes straight out of a
> > >>> tutorial on asp.net!
> > >>>
> > >>> Unfortunately, I do not at this time have the leisure to learn the
> > >>> ins and outs of the .net methods. All I need is the equivalent code
> > >>> to:
> > >>>
> > >>> Set Connect = Server.CreateObject("ADODB.Connection")
> > >>> Connect.Open "dbname","username","password"
> > >>> Query = "Select * from links Where ID = '" & id & "'"
> > >>> Set RS = Connect.Execute(Query) <-- I thought this is the dataset
> > >>> code = RS("code")
> > >>> title = RS("title")
> > >>> url = RS("url")
> > >>> email = RS("email")
> > >>> description = RS("description")
> > >>> retlink = RS("retlink")
> > >>> I would be very thankful if someone could help me write a the code
> > >>> to
> > >>> do the same thing under .net.
> > >>> Thanks
> > >>> Hermann
> > >>> "Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
> > >>> news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
> > >>>> Hi
> > >>>>
> > >>>> I need help at the very beginning. I have been writing classic ASP
> > >>>> for
> > >>>>
> > >>> some
> > >>>
> > >>>> time, but getting data out of a SQL database and displaying a
> > >>>> single value eludes me.
> > >>>>
> > >>>> So far I have the following code:
> > >>>>
> > >>>> Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
> > >>>> Source=SQLServer;Initial Catalog=database;")
> > >>>> Dim myCommand As New SqlDataAdapter("select Name from Products
> > >>>> where
> > >>>> code
> > >>> =
> > >>>
> > >>>> 0117", myConnection)
> > >>>>
> > >>>> Dim ds As New DataSet()
> > >>>> myCommand.Fill(ds, "Name")
> > >>>> to get a record out of the database. All I want to do now put the
> > >>>> Name in that record into a variable and use it in the HTML text. I
> > >>>> would
> > >>> appreciate
> > >>>
> > >>>> any help.
> > >>>>
> > >>>> Thank you
> > >>>> Hermann
> > >> --
> > >>
> > >> --
> > >> Matt Berther
> > >> http://www.mattberther.com
> > --
> > --
> > Matt Berther
> > http://www.mattberther.com
Hello John,

Thanks. That is exactly what I meant...

> there is a Page_Load event, which you can implement. I believe he
> wants you to put the code he provided into that event handler.
> private void Page_Load (object sender, System.EventArgs e)
> {
> // your code here
> }
> this is part of the 'code behind' technology in ASP.net.
> hope that helps,
> sincerely,
> J
> "Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
> news:eQCc71jMEHA.3972@.TK2MSFTNGP10.phx.gbl...
>> Hi
>>
>> Can you explain what you mean with "Page_Load"?
>> Thanks
>> Hermann
>> "Matt Berther" <mberther@.hotmail.com> wrote in message
>> news:%23C6uZOaMEHA.644@.tk2msftngp13.phx.gbl...
>>
>>> Hello Hermann,
>>>
>>> Try putting this in the .cs code-behind file in Page_Load.
>>>
>>>> Hi
>>>> Much Thanks for the code. I placed on a test page with the correct
>>>> variables, but received this error message:
>>>> Compiler Error Message: BC30684: 'SqlConnection' is a type and
>>>> cannot
>>>> be used as an expression
>>>> I have the following lines at the top of the page:
>>>>
>>>> <%@. import Namespace="System.Data" %>
>>>> <%@. import Namespace="System.Data.SqlClient" %>
>>>> Do I need to add anything else?
>>>> Thanks again
>>>> Hermann
>>>> "Matt Berther" <mberther@.hotmail.com> wrote in message
>>>> news:ONNBoITMEHA.2532@.TK2MSFTNGP10.phx.gbl...
>>>>> Hello Hermann,
>>>>>
>>>>> SqlConnection myConnection = new
>>>>>
>>>> SqlConnection("UID=dbuser;PWD=thepass;Data Source=server;Initial
>>>> Catalog=database;");
>>>>
>>>>> SqlCommand cmd = new SqlCommand("select name from products where
>>>>> code =
>>>>>
>>>> 0117", myConnection);
>>>>
>>>>> using (IDataReader rdr =
>>>>>
>>>> cmd.ExecuteReader(CommandBehavior.CloseConnection) )
>>>>
>>>>> {
>>>>> rdr.Read(); // if you want to loop through records, sorround this
>>>>> with
>>>> a while block
>>>>
>>>>> string code = rdr["code"].ToString();
>>>>> string title = rdr["title"].ToString();
>>>>> string url = rdr["url"].ToString();
>>>>> string email = rdr["email"].ToString();
>>>>> string description = rdr["description"].ToString();
>>>>> string retlink = rdr["retlink"].ToString();
>>>>> }
>>>>>> Hi
>>>>>>
>>>>>> Thanks for your help. The code example comes straight out of a
>>>>>> tutorial on asp.net!
>>>>>>
>>>>>> Unfortunately, I do not at this time have the leisure to learn
>>>>>> the ins and outs of the .net methods. All I need is the
>>>>>> equivalent code to:
>>>>>>
>>>>>> Set Connect = Server.CreateObject("ADODB.Connection")
>>>>>> Connect.Open "dbname","username","password"
>>>>>> Query = "Select * from links Where ID = '" & id & "'"
>>>>>> Set RS = Connect.Execute(Query) <-- I thought this is the dataset
>>>>>> code = RS("code")
>>>>>> title = RS("title")
>>>>>> url = RS("url")
>>>>>> email = RS("email")
>>>>>> description = RS("description")
>>>>>> retlink = RS("retlink")
>>>>>> I would be very thankful if someone could help me write a the
>>>>>> code
>>>>>> to
>>>>>> do the same thing under .net.
>>>>>> Thanks
>>>>>> Hermann
>>>>>> "Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
>>>>>> news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
>>>>>>> Hi
>>>>>>>
>>>>>>> I need help at the very beginning. I have been writing classic
>>>>>>> ASP for
>>>>>>>
>>>>>> some
>>>>>>
>>>>>>> time, but getting data out of a SQL database and displaying a
>>>>>>> single value eludes me.
>>>>>>>
>>>>>>> So far I have the following code:
>>>>>>>
>>>>>>> Dim myConnection As New
>>>>>>> SqlConnection("UID=dbuser;PWD=thepass;Data
>>>>>>> Source=SQLServer;Initial Catalog=database;")
>>>>>>> Dim myCommand As New SqlDataAdapter("select Name from Products
>>>>>>> where
>>>>>>> code
>>>>>> =
>>>>>>
>>>>>>> 0117", myConnection)
>>>>>>>
>>>>>>> Dim ds As New DataSet()
>>>>>>> myCommand.Fill(ds, "Name")
>>>>>>> to get a record out of the database. All I want to do now put
>>>>>>> the
>>>>>>> Name in that record into a variable and use it in the HTML text.
>>>>>>> I
>>>>>>> would
>>>>>> appreciate
>>>>>>
>>>>>>> any help.
>>>>>>>
>>>>>>> Thank you
>>>>>>> Hermann
>>>>> --
>>>>>
>>>>> --
>>>>> Matt Berther
>>>>> http://www.mattberther.com
>>> --
>>>
>>> --
>>> Matt Berther
>>> http://www.mattberther.com
--

--
Matt Berther
http://www.mattberther.com

Newby question

Hi
I need help at the very beginning. I have been writing classic ASP for some
time, but getting data out of a SQL database and displaying a single value
eludes me.
So far I have the following code:
Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
Source=SQLServer;Initial Catalog=database;")
Dim myCommand As New SqlDataAdapter("select Name from Products where code =
0117", myConnection)
Dim ds As New DataSet()
myCommand.Fill(ds, "Name")
to get a record out of the database. All I want to do now put the Name in
that record into a variable and use it in the HTML text. I would appreciate
any help.
Thank you
HermannFirst off, the Fill method is a method of the SqlDataAdapter class so to use
Fill, you'd have to create a data adapter first, but you don't need a
dataset for what you're doing. Use the ExecuteScalar() method of the
SqlCommand class to return a single value. Search the framework
documentation for "Obtaining a Single Value from a Database".
In order to use that server side variable in your HTML, do it just as you
would in classic ASP:
<p>Product name for product code 0117 is: <%= myVariable %>.</p>
Dale
"Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
> Hi
> I need help at the very beginning. I have been writing classic ASP for
some
> time, but getting data out of a SQL database and displaying a single value
> eludes me.
> So far I have the following code:
> Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
> Source=SQLServer;Initial Catalog=database;")
> Dim myCommand As New SqlDataAdapter("select Name from Products where code
=
> 0117", myConnection)
> Dim ds As New DataSet()
> myCommand.Fill(ds, "Name")
> to get a record out of the database. All I want to do now put the Name in
> that record into a variable and use it in the HTML text. I would
appreciate
> any help.
> Thank you
> Hermann
>
Hello Hermann,
An dataset is probably complete overkill for what you're trying to accomplis
h here.
Try this:
(c# code, but VB should be pretty similar)
SqlConnection myConnection = new SqlConnection("UID=dbuser;PWD=thepass;Data
Source=server;Initial Catalog=database;");
SqlCommand cmd = new SqlCommand("select name from products where code = 0117
", myConnection);
string s = (string)cmd.ExecuteScalar();
ExecuteScalar will receive one value from a database. It is up to you to cas
t it to the appropriate type.
HTH,
Matt Berther
http://www.mattberther.com
Hello DalePres,
Dale, in his code example, he was creating a SqlDataAdapter. The variable na
me was just wrong. ;)
> First off, the Fill method is a method of the SqlDataAdapter class so
> to use Fill, you'd have to create a data adapter first, but you don't
> need a dataset for what you're doing. Use the ExecuteScalar() method
> of the SqlCommand class to return a single value. Search the
> framework documentation for "Obtaining a Single Value from a
> Database".
> In order to use that server side variable in your HTML, do it just as
> you would in classic ASP:
> <p>Product name for product code 0117 is: <%= myVariable %>.</p>
> Dale
> "Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
> news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
>
> some
>
> =
>
> appreciate
>
--
Matt Berther
http://www.mattberther.com
You're right. I didn't catch that one at all. I guess that's why variable
naming is so important.
Dale
"Matt Berther" <mberther@.hotmail.com> wrote in message
news:OQF5$FAMEHA.140@.TK2MSFTNGP09.phx.gbl...
> Hello DalePres,
> Dale, in his code example, he was creating a SqlDataAdapter. The variable
name was just wrong. ;)
>
> --
> --
> Matt Berther
> http://www.mattberther.com
You should look at the Microsoft Data Access Application Block. This
simplifies the process a great deal. In any case, whether you use the
application block or not, if you just want one value, you can use the
ExecuteScalar method of the SQLCommand class to readily return it, or the
equivalent method of the SQLHelper class defined in the Data Access
Application Block.
Take a look at
http://www.microsoft.com/resources/...diences.asp#dev
Scroll down a ways, and you'll find a link to the Data Access Application
Block, as well as a wealth of other useful information.
"Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
> Hi
> I need help at the very beginning. I have been writing classic ASP for
some
> time, but getting data out of a SQL database and displaying a single value
> eludes me.
> So far I have the following code:
> Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
> Source=SQLServer;Initial Catalog=database;")
> Dim myCommand As New SqlDataAdapter("select Name from Products where code
=
> 0117", myConnection)
> Dim ds As New DataSet()
> myCommand.Fill(ds, "Name")
> to get a record out of the database. All I want to do now put the Name in
> that record into a variable and use it in the HTML text. I would
appreciate
> any help.
> Thank you
> Hermann
>
Hi
Thanks for your help. The code example comes straight out of a tutorial on
asp.net!
Unfortunately, I do not at this time have the leisure to learn the ins and
outs of the .net methods. All I need is the equivalent code to:
Set Connect = Server.CreateObject("ADODB.Connection")
Connect.Open "dbname","username","password"
Query = "Select * from links Where ID = '" & id & "'"
Set RS = Connect.Execute(Query) <-- I thought this is the dataset
code = RS("code")
title = RS("title")
url = RS("url")
email = RS("email")
description = RS("description")
retlink = RS("retlink")
I would be very thankful if someone could help me write a the code to do the
same thing under .net.
Thanks
Hermann
"Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
> Hi
> I need help at the very beginning. I have been writing classic ASP for
some
> time, but getting data out of a SQL database and displaying a single value
> eludes me.
> So far I have the following code:
> Dim myConnection As New SqlConnection("UID=dbuser;PWD=thepass;Data
> Source=SQLServer;Initial Catalog=database;")
> Dim myCommand As New SqlDataAdapter("select Name from Products where code
=
> 0117", myConnection)
> Dim ds As New DataSet()
> myCommand.Fill(ds, "Name")
> to get a record out of the database. All I want to do now put the Name in
> that record into a variable and use it in the HTML text. I would
appreciate
> any help.
> Thank you
> Hermann
>
Hello Hermann,
SqlConnection myConnection = new SqlConnection("UID=dbuser;PWD=thepass;Data
Source=server;Initial Catalog=database;");
SqlCommand cmd = new SqlCommand("select name from products where code = 0117
", myConnection);
using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
rdr.Read(); // if you want to loop through records, sorround this with a whi
le block
string code = rdr["code"].ToString();
string title = rdr["title"].ToString();
string url = rdr["url"].ToString();
string email = rdr["email"].ToString();
string description = rdr["description"].ToString();
string retlink = rdr["retlink"].ToString();
}
> Hi
> Thanks for your help. The code example comes straight out of a
> tutorial on asp.net!
> Unfortunately, I do not at this time have the leisure to learn the ins
> and outs of the .net methods. All I need is the equivalent code to:
> Set Connect = Server.CreateObject("ADODB.Connection")
> Connect.Open "dbname","username","password"
> Query = "Select * from links Where ID = '" & id & "'"
> Set RS = Connect.Execute(Query) <-- I thought this is the dataset
> code = RS("code")
> title = RS("title")
> url = RS("url")
> email = RS("email")
> description = RS("description")
> retlink = RS("retlink")
> I would be very thankful if someone could help me write a the code to
> do the same thing under .net.
> Thanks
> Hermann
> "Hermann W Ehlers" <hermann@.AThawkspoint.com> wrote in message
> news:usvpno9LEHA.340@.TK2MSFTNGP11.phx.gbl...
>
> some
>
> =
>
> appreciate
>
--
Matt Berther
http://www.mattberther.com
Hi
Much Thanks for the code. I placed on a test page with the correct
variables, but received this error message:
Compiler Error Message: BC30684: 'SqlConnection' is a type and cannot be
used as an expression
I have the following lines at the top of the page:
<%@. import Namespace="System.Data" %>
<%@. import Namespace="System.Data.SqlClient" %>
Do I need to add anything else?
Thanks again
Hermann
"Matt Berther" <mberther@.hotmail.com> wrote in message
news:ONNBoITMEHA.2532@.TK2MSFTNGP10.phx.gbl...
> Hello Hermann,
> SqlConnection myConnection = new
SqlConnection("UID=dbuser;PWD=thepass;Data Source=server;Initial
Catalog=database;");
> SqlCommand cmd = new SqlCommand("select name from products where code =
0117", myConnection);
> using (IDataReader rdr =
cmd.ExecuteReader(CommandBehavior.CloseConnection))
> {
> rdr.Read(); // if you want to loop through records, sorround this with
a while block
> string code = rdr["code"].ToString();
> string title = rdr["title"].ToString();
> string url = rdr["url"].ToString();
> string email = rdr["email"].ToString();
> string description = rdr["description"].ToString();
> string retlink = rdr["retlink"].ToString();
> }
>
> --
> --
> Matt Berther
> http://www.mattberther.com
Hello Hermann,
Try putting this in the .cs code-behind file in Page_Load.
> Hi
> Much Thanks for the code. I placed on a test page with the correct
> variables, but received this error message:
> Compiler Error Message: BC30684: 'SqlConnection' is a type and cannot
> be used as an expression
> I have the following lines at the top of the page:
> <%@. import Namespace="System.Data" %>
> <%@. import Namespace="System.Data.SqlClient" %>
> Do I need to add anything else?
> Thanks again
> Hermann
> "Matt Berther" <mberther@.hotmail.com> wrote in message
> news:ONNBoITMEHA.2532@.TK2MSFTNGP10.phx.gbl...
>
> SqlConnection("UID=dbuser;PWD=thepass;Data Source=server;Initial
> Catalog=database;");
>
> 0117", myConnection);
>
> cmd.ExecuteReader(CommandBehavior.CloseConnection))
>
> a while block
>
--
Matt Berther
http://www.mattberther.com