C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » Visual Studio »

how to retrieve and display data in database(access) in textbox with c#


Posted Date: 30 Sep 2008      Posted By: shxrainz      Member Level: Bronze     Points: 1   Responses: 3



can anyone helpme on how to retrive data and display it in a textbox?

I have created a student form to enter all the student information.
Then i want to call all the data being save in the database to be display in a textbox.
Can anyone show me how?
I already get how to insert the data to the database but i dont know how to retrieve and display the data back in a database.

i'm using visual studio 2005
with database access






Responses

Author: mahalakshmi    30 Sep 2008Member Level: GoldRating: 4 out of 54 out of 54 out of 54 out of 5     Points: 6

hi,

pageload()
{
OleDbConnection con=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/App_Data/jdb.mdb"));
OleDbCommand com = new OleDbCommand("select * from tbl", con);
con.Open();
OleDbDataReader data= com.ExecuteReader();
while (data.Read())
{
t1.text=data["fieldname1"].ToString();
t2.text=data["fieldname2"].ToString();
}
conn.close()
}

or
pageload()
{
OleDbConnection con=new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("~/App_Data/jdb.mdb"));
OleDbCommand com = new OleDbCommand("select * from tbl", con);
con.Open();
OleDbDataReader data= com.ExecuteReader();
data.Read()
t1.text=data["fieldname1"].ToString();
t2.text=data["fieldname2"].ToString();

conn.close()
}

or

use datacontrols like datagrid,repeater,...
bind db value with controls like

<asp:TextBox id="t1" Text='<%Eval("fieldname")%>' runat="server"/>

happy programming.



Author: SATHIYENTHIRA BOOPATHY.H    30 Sep 2008Member Level: BronzeRating: 3 out of 53 out of 53 out of 5     Points: 3

Hi,


You can try like the following code.

OledbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("~/App_Data"/student.mdb"));
OledbCommand comm = new OledbCommand("select name,rollno,grade from stud where rollno=1125");
conn.Open();
OledbDataReader reader = comm.ExecuteReader();
while(reader.Read())
{

name.Text = reader["name"].ToString();
rollno.Text = reader["rollno"].ToString();
grade.Text = reader["grade"].ToString();



}

conn.Close();

Thanks & Regards

H.Sathiyenthira Boopathy



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Converting a report to PDF fORMAT
Previous : Copy folders into its subfolders
Return to Discussion Forum
Post New Message
Category: Visual Studio

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use