Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello. I want to fetch data from database and display it in a textbox but data should be specific for different users ie for different users different data should be displayed...how to do?? please help me...
Posted
Comments
Nandakishore G N 8-Mar-13 0:47am    
what have you done till now paste it?
apjitin 8-Mar-13 1:28am    
This is only rough.Please help me out.
protected void Page_Load(object sender, EventArgs e)
{

string user=Userverify.GetUser(username);
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["userdatabase"].ConnectionString);
string command = "Select Portcode,Portname Userinfo.Username from Portinfo JOIN Userinfo ON Userinfo.Portcode=Portinfo.Portcode where Username=user";
SqlCommand cmd = new SqlCommand(command,con);
con.Open();
SqlDataAdapter dad = new SqlDataAdapter(cmd);
res = new DataTable();
dad.Fill(res);
while (res.Rows.Count==1)
{
tpc.Text = res.Rows[0]["Portcode"].ToString();
tpn.Text = res.Rows[0]["Portname"].ToString();
}
con.Close();
}
S. M. Ahasan Habib 8-Mar-13 1:34am    
You can store user specific data to your database and user wise fetch that data and set it to the textbox. If your datasource has non user specific data then you need to transform it to your business layer and display it to the page text box.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;

public partial class rnd : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(---------------------------------------);
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlCommand cmd = new SqlCommand("SELECT * FROM RNDTABLE", con);//collect userid/username using session or querystring and use where clause in this query
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
       textbox.Text=dt.Rows[0]["name"].Tostring();//return user ame in to textbox 
    }
}
 
Share this answer
 
Comments
apjitin 8-Mar-13 1:26am    
Thanx for your post.I am almost there but i would be using JOIN in my query and how to collect session of user
Avik Ghosh22 8-Mar-13 1:33am    
when an user enter your website using login page catch user id/name(which is unique) into session ....

example
________

http://www.aspdotnet-suresh.com/2012/11/aspnet-session-state-example-in-c-vbnet.html
apjitin 8-Mar-13 23:48pm    
yeah...it worked...thnx again...
Avik Ghosh22 8-Mar-13 1:34am    
welcome bro.... :)
You need to start from ado.net basics. Start here
Using ADO.NET for beginners[^]
A Beginner's Tutorial for Understanding ADO.NET[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900