943,985 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 33682
  • ASP.NET RSS
Sep 7th, 2005
0

Retrieve Information from Database & Display into ASP.NET Web Controls Textbox

Expand Post »
I am creating a update member page. I would like the page to auto retrieve the information he or she originally used while registering on my site and display them into the individual textboxes of the update profile page, this is to prevent the hassle to rekey in every individual details and allow the user to edit what he or she wants before it is updated into the database.

I am having problem retrieving information from the database and displaying them into the individual asp.net web text boxes. I am trying to use SQL DataAdapter or SQL Reader, but both fails. Some help to resolve this problem please, an example with code snippets will be very much appreciated. :rolleyes:

ASP.NET Syntax (Toggle Plain Text)
  1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3. displayrecord()
  4. End If
  5.  
  6. Private Sub displayrecord()
  7. SqlConnection1.Open()
  8. Dim SqlDataAdapter1 As New SqlDataAdapter("SELECT * FROM Member", SqlConnection1)
  9. Dim objReader As SqlDataReader
  10. Dim SqlCommand1 As New SqlCommand("SELECT * FROM Member", SqlConnection1)
  11. SqlDataAdapter1.Fill(dsMember)
  12. objReader = SqlCommand1.ExecuteReader()
  13.  
  14. objReader.Read()
  15. txtbox_user.Text = objReader("MemberUserName")
  16. txtbox_password.Text = objReader("MemberPassword")
  17. txtbox_confirmpass.Text = objReader("MemberPassword")
  18. txtbox_name.Text = objReader("MemberName")
  19. txtbox_birthdate.Text = objReader("MemberDOB")
  20. txtbox_nric.Text = objReader("NRIC")
  21. txtbox_address.Text = objReader("MemberAddress")
  22. txtbox_contact.Text = objReader("MemberPhone")
  23. txtbox_email.Text = objReader("MemberEmail")
  24. Dropdown_Gender.SelectedValue = objReader("Gender")
  25. DropDown_Age.SelectedValue = objReader("Age")
  26. DropDown_Income.SelectedValue = objReader("Income")
  27. DropDown_Children.SelectedValue = objReader("NumofChildren")
  28. DropDown_HearUs.SelectedValue = objReader("HowDidYouKnowAboutUs")
  29. objReader.Close()
  30. SqlConnection1.Close()
  31. End Sub
Last edited by Paladine; Sep 8th, 2005 at 1:45 pm. Reason: PLEASE USE CODE BLOCKS! Thx
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Naters_uk is offline Offline
50 posts
since Jun 2005
Sep 8th, 2005
0

Re: Retrieve Information from Database & Display into ASP.NET Web Controls Textbox

you can use data reader for this,

command = new SqlCommand("SELECT * FROM Member",sqlConnection );
command.CommandType = CommandType.StoredProcedure;
try
{
     sqlConnection.Open();
     reader=command.ExecuteReader();
     while (reader.Read())
{
//if it is a text box 
txtbox_user.Text=reader.IsDBNull(reader.GetOrdinal("MemberUserName"))? null: reader["MemberUserName"].ToString();
//if it is a dropdown put defalut value 0 or 1, what ever value you use.
DropDown_Children.SelectedValue=Convert.ToString(reader.IsDBNull(reader.GetOrdinal("NumofChildren")) ? (int)0 : (int)reader["NumofChildren"]);						
					
}
}
catch(Exception ex)
{
   throw new Exception(ex.Message);
}
finally
{
   reader.Close();
   sqlConnection.Close();
}
Last edited by Paladine; Sep 8th, 2005 at 1:47 pm. Reason: PLEASE USE CODE BLOCKS - THANKS!!!!!!!!!!
Reputation Points: 10
Solved Threads: 0
Light Poster
aish is offline Offline
26 posts
since Aug 2005
Sep 8th, 2005
0

Re: Retrieve Information from Database & Display into ASP.NET Web Controls Textbox

Hi Aish,

I do not understand what is this line of code is doing except a rough guess that it is trying to read the column MemberUserName. Would you mind explaining it to me? In addition, i am writing this code using ASP.NET with VB. Would you mind tuning this part of the codes that i have quoted into ASP.NET with VB as i am having a hard time trying to fix it into that. :o

//if it is a text box
txtbox_user.Text=reader.IsDBNull(reader.GetOrdinal("MemberUserName"))? null: reader["MemberUserName"].ToString();
//if it is a dropdown put defalut value 0 or 1, what ever value you use.
DropDown_Children.SelectedValue=Convert.ToString(reader.IsDBNull(reader.GetOrdinal("NumofChildren")) ? (int)0 : (int)reader["NumofChildren"]);





Quote originally posted by aish ...
you can use data reader for this,

command = new SqlCommand("SELECT * FROM Member",sqlConnection );
command.CommandType = CommandType.StoredProcedure;
try
{
sqlConnection.Open();
reader=command.ExecuteReader();
while (reader.Read())
{
//if it is a text box
txtbox_user.Text=reader.IsDBNull(reader.GetOrdinal("MemberUserName"))? null: reader["MemberUserName"].ToString();
//if it is a dropdown put defalut value 0 or 1, what ever value you use.
DropDown_Children.SelectedValue=Convert.ToString(reader.IsDBNull(reader.GetOrdinal("NumofChildren")) ? (int)0 : (int)reader["NumofChildren"]);

}
}
catch(Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
reader.Close();
sqlConnection.Close();
}
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Naters_uk is offline Offline
50 posts
since Jun 2005
Sep 11th, 2005
0

Re: Retrieve Information from Database & Display into ASP.NET Web Controls Textbox

Naters,

I've seen an error already, look at the code.

Why do you have a closing "End If" on the Sub Page_Load were you don't have an opening If? That should be End Sub

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

displayrecord()
End If


Post the the SQL error message that way it is easy to troubleshoot.

Dexter Zafra
http://www.myasp-net.com
Reputation Points: 10
Solved Threads: 3
Junior Poster in Training
dexterz is offline Offline
86 posts
since Feb 2005
Aug 7th, 2006
0

Re: Retrieve Information from Database & Display into ASP.NET Web Controls Textbox

Quote originally posted by Naters_uk ...
I am creating a update member page. I would like the page to auto retrieve the information he or she originally used while registering on my site and display them into the individual textboxes of the update profile page, this is to prevent the hassle to rekey in every individual details and allow the user to edit what he or she wants before it is updated into the database.

I am having problem retrieving information from the database and displaying them into the individual asp.net web text boxes. I am trying to use SQL DataAdapter or SQL Reader, but both fails. Some help to resolve this problem please, an example with code snippets will be very much appreciated. :rolleyes:

ASP.NET Syntax (Toggle Plain Text)
  1. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.  
  3. displayrecord()
  4. End If
  5.  
  6. Private Sub displayrecord()
  7. SqlConnection1.Open()
  8. Dim SqlDataAdapter1 As New SqlDataAdapter("SELECT * FROM Member", SqlConnection1)
  9. Dim objReader As SqlDataReader
  10. Dim SqlCommand1 As New SqlCommand("SELECT * FROM Member", SqlConnection1)
  11. SqlDataAdapter1.Fill(dsMember)
  12. objReader = SqlCommand1.ExecuteReader()
  13.  
  14. objReader.Read()
  15. txtbox_user.Text = objReader("MemberUserName")
  16. txtbox_password.Text = objReader("MemberPassword")
  17. txtbox_confirmpass.Text = objReader("MemberPassword")
  18. txtbox_name.Text = objReader("MemberName")
  19. txtbox_birthdate.Text = objReader("MemberDOB")
  20. txtbox_nric.Text = objReader("NRIC")
  21. txtbox_address.Text = objReader("MemberAddress")
  22. txtbox_contact.Text = objReader("MemberPhone")
  23. txtbox_email.Text = objReader("MemberEmail")
  24. Dropdown_Gender.SelectedValue = objReader("Gender")
  25. DropDown_Age.SelectedValue = objReader("Age")
  26. DropDown_Income.SelectedValue = objReader("Income")
  27. DropDown_Children.SelectedValue = objReader("NumofChildren")
  28. DropDown_HearUs.SelectedValue = objReader("HowDidYouKnowAboutUs")
  29. objReader.Close()
  30. SqlConnection1.Close()
  31. End Sub
Regarding this set of codes, can i know how to display the records using OleDbConnection, OleDbReader?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
frossie is offline Offline
3 posts
since Aug 2006
Sep 1st, 2009
0

Re: Retrieve Information from Database & Display into ASP.NET Web Controls Textbox

I have got the same problem, if anyone helps you they are helping me as well
rmc
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rmc is offline Offline
2 posts
since Sep 2009
Dec 6th, 2010
0
Re: Retrieve Information from Database & Display into ASP.NET Web Controls Textbox
Naters_uk,

Thanks.. I got the answer from your post!!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kuracha is offline Offline
5 posts
since Dec 2010
Dec 6th, 2010
0
Re: Retrieve Information from Database & Display into ASP.NET Web Controls Textbox
frossie,

your post is 3 years ago.. I'll answer it anyway..

just add:

Imports system.Data.OleDB -- for VB
using System.Data.OleDB -- for C#

then revise the code by changing Sql to OleDB..
EX: SqlCommand to OleDBCommand.

Hope this one helps!
Last edited by kuracha; Dec 6th, 2010 at 5:57 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kuracha is offline Offline
5 posts
since Dec 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: clearing textbox
Next Thread in ASP.NET Forum Timeline: gridview





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC