Click here to Skip to main content
15,904,339 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do i display data from database via textbox and how to edit that value
Posted
Comments
By coding. Did you try?
Nirav Prabtani 13-Apr-14 14:06pm    
:) :) :) :P I don't think he tried...
Sergey Alexandrovich Kryukov 13-Apr-14 16:09pm    
First of all, when you say "TextBox", the question is: which one? Full type name, please. There are different types named "TextBox". Which one?
—SA

Open Visual Studio (you can use NotePad as well, but it's just easy) and start writing code. That's it.

Ok, that's not what you expect. But this is what you get when you don't even care to explain what you exactly want to do and what have you have tried so far.

My guess is you are looking for cooked code here but I am sorry to disappoint you that is not going to happen.

Please go back and show us what you have done and then come back if you face issues.

People would be more than happy to help you here.
 
Share this answer
 
Comments
Bajpangosh 13-Apr-14 14:15pm    
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["VeinConnectionString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)
{
bindata();
}

}


public void bindata()
{
SqlCommand cmd;
SqlDataReader dr;
cmd = new SqlCommand("select * from shops where Id=" + Request.QueryString["Id"].ToString());
cmd.Connection = con;
cmd.ExecuteNonQuery();
dr = cmd.ExecuteReader();
while (dr.Read())
{
Shops.Text = dr["Shops"].ToString();
Reviews.Text = dr["Reviews"].ToString();

Website.Text = dr["Website"].ToString();
Fbpage.Text = dr["Fbpage"].ToString();
Phone.Text = dr["Phone"].ToString();
Email.Text = dr["Email"].ToString();
Place.Text = dr["Place"].ToString();
Latitude.Text = dr["Latitude"].ToString();

Longitude.Text = dr["Longitude"].ToString();

}





}
Bajpangosh 13-Apr-14 14:16pm    
here is my cs code but how to display these fetched datas on aspx page..?
 
Share this answer
 
v2
Comments
Manas Bhardwaj 13-Apr-14 16:21pm    
+5!
Maciej Los 13-Apr-14 16:43pm    
Thank you ;)
Quote:
here is my cs code but how to display these fetched datas on aspx page..?
You are already showing on aspx controls, I believe.
C#
Shops.Text =  dr["Shops"].ToString();
Reviews.Text = dr["Reviews"].ToString();

Website.Text = dr["Website"].ToString();
Fbpage.Text = dr["Fbpage"].ToString();
Phone.Text = dr["Phone"].ToString();
Email.Text = dr["Email"].ToString();
Place.Text = dr["Place"].ToString();
Latitude.Text = dr["Latitude"].ToString();

Longitude.Text = dr["Longitude"].ToString();

Here these are aspx controls and you are already assigning the values from database.
 
Share this answer
 
v2
Comments
Bajpangosh 13-Apr-14 14:27pm    
but help me to display these fetched datas on text box.

just drag the textbox and change the id. is it works or teach me the right way :(
Yeah you can drag one TextBox from Toolbar, else you can write directly...

One TextBox code would look like...

<asp:TextBox ID="txtSomeName" runat="server"></asp:TextBox>

Then from code, you can assign some value like...

txtSomeName.Text = dr["Shops"].ToString();
Bajpangosh 13-Apr-14 14:46pm    
run time it's shows an error :(

An exception of type 'System.NullReferenceException' occurred in App_Web_bly0ny4p.dll but was not handled in user code


it's pop-out from

cmd = new SqlCommand("select * from shops where Id=" + Request.QueryString["Id"].ToString());
That means there is no query string. It is null. So, NullReferenceException is coming.

Always check for null like...

if(Request.QueryString["Id"] != null && !string.IsNullOrEmpty(Request.QueryString["Id"].ToString()))
{
cmd = new SqlCommand("select * from shops where Id=" + Request.QueryString["Id"].ToString());
}
Bajpangosh 13-Apr-14 22:10pm    
thx for helping me bro. maybe it's works but am a newbie in visual studio :(

when i put this code on cs

it's shows an compile error

//Error 19 Use of unassigned local variable 'cmd'
Use ADO.NET:
http://en.wikipedia.org/wiki/Ado.net[^],
http://msdn2.microsoft.com/en-us/library/aa286484.aspx[^].

This short and clear CodeProject article can help you to get started in no time: Using ADO.NET for beginners[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900