How To Get data in textbox from database?

Posted by Sf_Hussain786 under ASP.NET on 3/14/2012 | Points: 10 | Views : 168360 | Status : [Member] | Replies : 11
Hi,

Can anybody tell me how to get data in textbox from sql server database and write all data connectivity code in .cs page and call data in textbox code in aspx page,

Regards,
sf_hussain786

sf_hussain786


Responses

Posted by: Patel28rajendra on: 3/14/2012 [Member] Starter | Points: 25

Up
0
Down
Hi

sf_hussain786

You have to write sql connection and fire select query from database
and you can use Data Reader/Dataset/DataTable and assing particular value to textbox text


you can write code something like this

string s = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(s);
SqlCommand cmd = new SqlCommand("select * from table where Id='" + value + "'", con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@Id",value);

cmd.Connection = con;
con.Open();

SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
TextBox1.Text = dr["username"].ToString();
TextBox2.Text = dr["password"].ToString();
TextBox3.Text = dr["fname"].ToString();
TextBox4.Text = dr["gender"].ToString();
}

dr.Close();
con.Close();


If it helps Mark as Answer

Thanks
Rajendra Patel

R D Patel

Sf_Hussain786, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hmanjarawala on: 3/15/2012 [Member] Bronze | Points: 25

Up
0
Down
Hi check this:

http://www.daniweb.com/web-development/aspnet/threads/31919
http://forums.asp.net/t/1042463.aspx/1
http://bytes.com/topic/asp-net/answers/319474-displaying-data-database-textboxes

Himanshu Manjarawala
Sr. Software Engineer@AutomationAnywhere
http://fieredotnet.wordpress.com/

Sf_Hussain786, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 3/15/2012 [Member] Silver | Points: 25

Up
0
Down
Hi Sf_Hussain786,
Refer to :
http://forums.asp.net/t/1042463.aspx/1

Thanks,
Sanjay

Sf_Hussain786, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Patel28rajendra on: 3/15/2012 [Member] Starter | Points: 25

Up
0
Down
HI

see this link

http://www.java2s.com/Code/ASP/ADO.net-Database/ReaddatafromdatabaseincodebehindC.htm

R D Patel

Sf_Hussain786, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumaran1987 on: 1/22/2013 [Member] Starter | Points: 25

Up
0
Down
How to Retrieve Data from database and view datas in label or textbox using ASP.NET and SQL
see here --> http://www.kumaran198726.com/2013/01/how-to-retrieve-data-from-database-and.html

Kumaran K

Sf_Hussain786, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumaran1987 on: 1/22/2013 [Member] Starter | Points: 25

Up
0
Down
How to Retrieve Data from database and view datas in label or textbox using ASP.NET and SQL
see here --> http://www.kumaran198726.com/2013/01/how-to-retrieve-data-from-database-and.html

Kumaran K

Sf_Hussain786, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Satyapriyanayak on: 1/23/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Refer
http://www.c-sharpcorner.com/UploadFile/satyapriyanayak/show-the-data-of-respective-columns-of-a-database-in-textbox/

If this post helps you mark it as answer
Thanks

Sf_Hussain786, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayachandradotnet on: 5/15/2013 [Member] Starter | Points: 25

Up
0
Down
Dim strConnString As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString
Dim con As New SqlConnection(strConnString)
Dim str As String = "select * from Employees1 where EmployeeID = " & txtEmployeeID.Text
Dim cmd As SqlCommand = New SqlCommand(str, con)
cmd.Connection = con
con.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
While (dr.Read())
txtFirstName.Text = dr("FirstName").ToString()
txtLastName.Text = dr("LastName").ToString()
txtBirthDate.Text = dr("Birthdate").ToString()
txtCity.Text = dr("City").ToString()
txtCountry.Text = dr("Country").ToString()
End While
dr.Close()
con.Close()

Sf_Hussain786, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tty420 on: 5/23/2013 [Member] Starter | Points: 25

Up
0
Down
hello sir SqlDataReader dr = cmd.ExecuteReader(); not support this reader code plse help me

Sf_Hussain786, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bageshkumarbagi on: 5/23/2013 [Member] Starter | Points: 25

Up
0
Down
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
TextBox1.Text = dr[0].ToString();
TextBox2.Text = dr[1].ToString();
TextBox3.Text = dr[2].ToString();
TextBox4.Text = dr[3].ToString();
}

use this.



Thanks,
Bagesh Kumar Singh

Thanks,
Bagesh Kumar Singh
Mark as answer if you have been satisfied

Sf_Hussain786, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: perfectchourasia-9163 on: 5/28/2013 [Member] Starter | Points: 25

Up
0
Down
Get data in dataset,sqlreader,datatable ....

and then Fill value to textbox

TextBox1.Text = dr["username"].ToString();

Values goes right to left...

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

Sf_Hussain786, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response