Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

.NET Forum


You are currently viewing our .NET Forum as a guest. Please register to participate.
Login



Reply
use DB fields as Global Variable
Old 09-04-2006, 12:27 PM use DB fields as Global Variable
Experienced Talker

Posts: 34
Trades: 0
I connect to SQLDB as Follow code
-------------
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:121ConnectionString %>"
SelectCommand="SELECT [text], [count] FROM [Test] WHERE ([id] = @id)">
<SelectParameters>
--------------
and bind data in DAta list like this
-------
<asp:Label ID="textLabel" runat="server" Text='<%# Eval("count") %>'></asp:Label><br />
-----
I want to access the value of DB fiels from code bbehind.I do not want to use Eval command, I want to work with them as a variable. i.e work with "countt" field as Golbal variable on my weform and change it's valut to i.e "count" * 15 = 100
what should I do?
s2002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 09-09-2006, 09:02 PM Re: use DB fields as Global Variable
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
Don't use a DataSource control.

You'll need to use ADO Objects instead, i.e.

Code:
SqlConnection MyConnection = new SqlConnection("ConnectionString");
SqlCommand MyCommand = new SqlCommand("SELECT * FROM Table", MyConnection);
MyCommand.CommandType = CommandType.Text;
 
MyConnection.Open();
try
{
   // Use the SqlCommand method here to get the data that you want. You'd usually read it into an SqlDataReader or bind it to a control or something.
}
finally
{
   MyConnection.Close();
}
It's best to put that sort of code into it's own set of classes that will be a DAL (Data Access Layer) and then the DAL classes are used by a set of BLL Classess (Business Logic Layer) which are in turn used by the User Interface Layer. Another way of doing it would be to use Table Adapters.

For more info, take a look at these tutorials:
ASP.NET Developer Center: Data Access: Tutorial 1: Creating a Data Access Layer
ASP.NET Developer Center: Data Access: Tutorial 2: Creating a Business Logic Layer
ASP.NET Developer Center: Tutorial 3: Master Pages and Site Navigation
ASP.NET Developer Center: Tutorial 4: Displaying Data With the ObjectDataSource

Although personally, I'd ignore their bit about ObjectDataSource and just call the Business Logic Layer classes from the code-behind files. DataSource controls can be a pain to work with...
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Reply     « Reply to use DB fields as Global Variable
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09802 seconds with 12 queries