hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Help with ASP.net and tableAdapters
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Help with ASP.net and tableAdapters

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 04-04-2010, 03:02 AM
HardLayers HardLayers is offline
Junior Guru Wannabe
 
Join Date: Mar 2008
Location: Saudi Arabia
Posts: 80

Help with ASP.net and tableAdapters


Hello Everyone,

I'm creating a web site application through VWD 2008 express edition.

what i've done so far:
1- created a database MDF file in App_data
2- Created a dataset in root directory
3- thrown some tables from my database into that dataset
4- created a query on the users tableAdapter to getDataByUsername

this getDataByUsername(@username) query text is :
Code:
SELECT user_id, password, email, creationdate, lastaccess, dept_id, fname, lname, status FROM users WHERE (username = @username)
ofcourse, the type of the query is an SQL statement (SELECT which returns rows)
but should return only one row.


anyway,
what i'm trying to do in one code-behind file is this.
Code:
using eMIS.eMISDBTableAdapters;

///////////////////////
usersTableAdapter userAD = new usersTableAdapter();
////////////////////////////////
public static void populateUserInfo(string user)
        {
            HttpContext.Current.Session.Add("userid",userAD.GetDataByUsername(user).user_idColumn..ToString());
            HttpContext.Current.Session.Add("username",user);
        }

the problem i'm facing is with this code
Code:
userAD.GetDataByUsername(user).user_idColumn..ToString()
i think the the adapter thinks the query is returning more than one row so i can't just use the .user_idColumn to get the value of it.


in other scenarios i've used userAD.checkUser(user, pass); to return only one value (not only one row) which then returned an integer = 1 if there's a user with that username and password in the database.


if someone could help me with this i'll really appreciate it.



Regards,
Mohannad

Reply With Quote


Sponsored Links
  #2  
Old 04-04-2010, 10:14 AM
Host Ahead Host Ahead is offline
Junior Guru Wannabe
 
Join Date: Jan 2010
Location: Spain
Posts: 72
Hi,

It returns indeed an array of items. If you're sure it only returns 1 item in this array, you should first return the first (and thus only) item of it:

userAD.GetDataByUsername(user)(0).user_idColumn.ToString()

I have not tested this, as I normally don't work with tableAdapaters but this should logically work.

Let me know if you have any problems.

__________________
Quality hosting and domain names
Multi platform shared hosting
Affordable domain names
Host Ahead: Your partner on the web

Reply With Quote
  #3  
Old 04-05-2010, 03:27 AM
HardLayers HardLayers is offline
Junior Guru Wannabe
 
Join Date: Mar 2008
Location: Saudi Arabia
Posts: 80
Quote:
Originally Posted by Host Ahead View Post
Hi,

It returns indeed an array of items. If you're sure it only returns 1 item in this array, you should first return the first (and thus only) item of it:

userAD.GetDataByUsername(user)(0).user_idColumn.ToString()

I have not tested this, as I normally don't work with tableAdapaters but this should logically work.

Let me know if you have any problems.

You rock
it really worked with
GetDataByUsername(user)[0]
[ instead of (


thanks alot

Reply With Quote
Sponsored Links
  #4  
Old 04-05-2010, 08:41 AM
Host Ahead Host Ahead is offline
Junior Guru Wannabe
 
Join Date: Jan 2010
Location: Spain
Posts: 72
Oh yes,

that's right. I normally program in VB but in C# it's the square bracket.

Glad to help

__________________
Quality hosting and domain names
Multi platform shared hosting
Affordable domain names
Host Ahead: Your partner on the web

Reply With Quote
  #5  
Old 04-17-2010, 01:06 PM
ShyGuy82 ShyGuy82 is offline
Web Hosting Guru
 
Join Date: Oct 2006
Posts: 310
I would personally use LINQ to SQL instead of ADO.NET datatables and adapters.

Reply With Quote
Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
UNLIMITED ASP.net/Windows Reseller only $39.95 or asp.net w/FREE sql2005 from $7.96 appliedi Shared Hosting Offers 0 01-07-2007 03:48 PM
[ASP.NET with MSQL] VS [ASP.NET with SQL Server] holy_joy Hosting Security and Technology 4 05-11-2006 04:09 PM
IHostASP.NET - Huge ASP/ASP.NET & MSSQL2K Hosting Sale!!! GrindKore Shared Hosting Offers 0 05-15-2005 10:05 PM
DicountASP.NET launches Obout Treeview ASP and ASP.NET Component dasp Shared Hosting Offers 0 06-11-2004 01:56 PM

Related posts from TheWhir.com
Title Type Date Posted


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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 Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?