•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 427,430 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,632 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 14657 | Replies: 4
![]() |
•
•
Join Date: Jun 2005
Posts: 50
Reputation:
Rep Power: 4
Solved Threads: 0
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:
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:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
displayrecord()
End If
Private Sub displayrecord()
SqlConnection1.Open()
Dim SqlDataAdapter1 As New SqlDataAdapter("SELECT * FROM Member", SqlConnection1)
Dim objReader As SqlDataReader
Dim SqlCommand1 As New SqlCommand("SELECT * FROM Member", SqlConnection1)
SqlDataAdapter1.Fill(dsMember)
objReader = SqlCommand1.ExecuteReader()
objReader.Read()
txtbox_user.Text = objReader("MemberUserName")
txtbox_password.Text = objReader("MemberPassword")
txtbox_confirmpass.Text = objReader("MemberPassword")
txtbox_name.Text = objReader("MemberName")
txtbox_birthdate.Text = objReader("MemberDOB")
txtbox_nric.Text = objReader("NRIC")
txtbox_address.Text = objReader("MemberAddress")
txtbox_contact.Text = objReader("MemberPhone")
txtbox_email.Text = objReader("MemberEmail")
Dropdown_Gender.SelectedValue = objReader("Gender")
DropDown_Age.SelectedValue = objReader("Age")
DropDown_Income.SelectedValue = objReader("Income")
DropDown_Children.SelectedValue = objReader("NumofChildren")
DropDown_HearUs.SelectedValue = objReader("HowDidYouKnowAboutUs")
objReader.Close()
SqlConnection1.Close()
End Sub Last edited by Paladine : Sep 8th, 2005 at 12:45 pm. Reason: PLEASE USE CODE BLOCKS! Thx
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 12:47 pm. Reason: PLEASE USE CODE BLOCKS - THANKS!!!!!!!!!!
•
•
Join Date: Jun 2005
Posts: 50
Reputation:
Rep Power: 4
Solved Threads: 0
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"]);
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();
}
•
•
Join Date: Feb 2005
Location: Los Angeles, CA
Posts: 86
Reputation:
Rep Power: 4
Solved Threads: 2
Re: Retrieve Information from Database & Display into ASP.NET Web Controls Textbox
#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
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
Ex-designz.net
•
•
Join Date: Aug 2006
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
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:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load displayrecord() End If Private Sub displayrecord() SqlConnection1.Open() Dim SqlDataAdapter1 As New SqlDataAdapter("SELECT * FROM Member", SqlConnection1) Dim objReader As SqlDataReader Dim SqlCommand1 As New SqlCommand("SELECT * FROM Member", SqlConnection1) SqlDataAdapter1.Fill(dsMember) objReader = SqlCommand1.ExecuteReader() objReader.Read() txtbox_user.Text = objReader("MemberUserName") txtbox_password.Text = objReader("MemberPassword") txtbox_confirmpass.Text = objReader("MemberPassword") txtbox_name.Text = objReader("MemberName") txtbox_birthdate.Text = objReader("MemberDOB") txtbox_nric.Text = objReader("NRIC") txtbox_address.Text = objReader("MemberAddress") txtbox_contact.Text = objReader("MemberPhone") txtbox_email.Text = objReader("MemberEmail") Dropdown_Gender.SelectedValue = objReader("Gender") DropDown_Age.SelectedValue = objReader("Age") DropDown_Income.SelectedValue = objReader("Income") DropDown_Children.SelectedValue = objReader("NumofChildren") DropDown_HearUs.SelectedValue = objReader("HowDidYouKnowAboutUs") objReader.Close() SqlConnection1.Close() End Sub
Regarding this set of codes, can i know how to display the records using OleDbConnection, OleDbReader?
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
adult advertising ajax asp blog browser browsing community daniweb data database design development devices dom domains firefox google india intel internet java legal linux marketing microsoft mozilla msdn msn multimedia news php privacy report research search security software sql sun survey video w3c web web development wiki xml xoap yahoo
- ASP.NET Web/ Applications Developer - Macclesfield (Software Development Job Offers)
- Need ASP.NET Web Developers - URGENT (ASP.NET)
- ASP .NET Web Application setup? (VB.NET)
- Drag and Drop ASP.NET 2.0 Web Parts in FireFox (ASP.NET)
- Asp.Net and Web Services on Linux (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: from DB
- Next Thread: Email send in ASP.NET with "Accept en Deny" link


Linear Mode