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

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

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

 
0
  #1
Sep 7th, 2005
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:

  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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 26
Reputation: aish is an unknown quantity at this point 
Solved Threads: 0
aish's Avatar
aish aish is offline Offline
Light Poster

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

 
0
  #2
Sep 8th, 2005
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!!!!!!!!!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 50
Reputation: Naters_uk is an unknown quantity at this point 
Solved Threads: 0
Naters_uk Naters_uk is offline Offline
Junior Poster in Training

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

 
0
  #3
Sep 8th, 2005
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"]);





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();
}
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 86
Reputation: dexterz is an unknown quantity at this point 
Solved Threads: 3
dexterz dexterz is offline Offline
Junior Poster in Training

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

 
0
  #4
Sep 11th, 2005
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
Dexter Zaf
Ex-designz.net
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 3
Reputation: frossie is an unknown quantity at this point 
Solved Threads: 0
frossie frossie is offline Offline
Newbie Poster

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

 
0
  #5
Aug 7th, 2006
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:

  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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 2
Reputation: rmc is an unknown quantity at this point 
Solved Threads: 0
rmc rmc is offline Offline
Newbie Poster

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

 
0
  #6
Sep 1st, 2009
I have got the same problem, if anyone helps you they are helping me as well
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC