473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to fetch some of the data from databse to textbox in a form.

i hav a form. there is a roll.no textbox,i want that when i enter a roll no. ,that rollno if exist in a table in the database then it bring its corresponding values like name,add,etc to the textbox in the same form.
hope my query is clear.
plz reply as soon as possible.thanks......
Jul 25 '08 #1
11 3099
r035198x
13,262 8TB
Do you know how to connect to a database using ADO.NET?
Jul 25 '08 #2
Do you know how to connect to a database using ADO.NET?
yes i know the connectivity steps.i am using sqlserver.my query is how to get the data from database to the textbox in a form.i know how to display the data from database to gridveiw but i dont know how to display it into textbox from database.
Jul 25 '08 #3
r035198x
13,262 8TB
i hav a form. there is a roll.no textbox,i want that when i enter a roll no. ,that rollno if exist in a table in the database then it bring its corresponding values like name,add,etc to the textbox in the same form.
hope my query is clear.
plz reply as soon as possible.thanks......
Then just write a select that filters according to the entered rollno and run that against the database when an appropriate event is fired.
Post your code if you still get problems with it.
Jul 25 '08 #4
Curtis Rutland
3,256 Expert 2GB
...i know how to display the data from database to gridveiw but i dont know how to display it into textbox from database.
Well, we have two articles that you might want to read. After that, you should be able to figure out how to fill a textbox from a database.

Article 1
Article 2
Jul 25 '08 #5
Well, we have two articles that you might want to read. After that, you should be able to figure out how to fill a textbox from a database.

Article 1
Article 2
thanks for the articles.The matter u hav given me,i already know that,what i want to know is described below.
i m using C# .net and working on window forms.
my code is-

SqlConnection cn = new SqlConnection();
cn.ConnectionString = "Data Source= abc ;Database=def ;uid=ghh ;pwd=ty ";
cn.Open();
string sql="select * from order where order_no=@order";
SqlCommand cmd=new SqlCommand(sql,cn);
cmd.Parameters.AddWithValue("@order",Convert.ToInt 32(textBox1.Text);
SqlDataAdapter da=new SqlDataAdapter(cmd);
da.Fill(dt); /*dt is a instance of DataTable*/
dataGridView1.DataSource=dt;
cn.Close();
.................................................. ....................................
i want to show the values in textbox respectively.
i know how to show the data in gridview but i want to know how can i get the data in textBox not in dataGridview.
Jul 25 '08 #6
Curtis Rutland
3,256 Expert 2GB
So, instead of making the DataTable a datasource for the gridview, loop through it and put the contents in a textbox. Or, if you are just selecting one value, you can use the ExecuteScalar method that I discuss in the 2nd article. Just cast the return value as a string, and then put that string in a textbox. You're making this harder than it has to be.
Jul 25 '08 #7
So, instead of making the DataTable a datasource for the gridview, loop through it and put the contents in a textbox. Or, if you are just selecting one value, you can use the ExecuteScalar method that I discuss in the 2nd article. Just cast the return value as a string, and then put that string in a textbox. You're making this harder than it has to be.
thanks i got it,i will try it.
Jul 25 '08 #8
thanks i got it,i will try it.
thank u ,its working.
Jul 25 '08 #9
Curtis Rutland
3,256 Expert 2GB
Glad to help.
Jul 25 '08 #10
Glad to help.
I hav a problem in sql query.I m using C#.net and working on window form,Database is SqlSever.
There is a table tracking which has key_no,status as its field.
There is another table master which has slno,key_no,etc as its field.

In my form i hav a textbox in which one enters slno,so using this slno i want to get key_no from master table using Select query and then use this key_no to update the status in tracking table.

I have used the code which is written below,but it is not updating the value in the table tracking.

CODE-

SqlConnection cn = new SqlConnection();
cn.ConnectionString = "Data Source= abc ;Database= def;uid=pro;pwd=ghg";
cn.Open();
string sql = "update rock set status='INVG' where key_no=(select key_no from master where slno=@slno)";
SqlCommand cmd= new SqlCommand(sql, cn);
cmd.Parameters.AddWithValue("@slno", Convert.ToInt32(textBox2.Text));
SqlDataAdapter ds = new SqlDataAdapter(k);
ds.Fill(dd); /*dd is a instance of DataTable*/
MessageBox.Show("Record updated");
cn.Close();
Jul 26 '08 #11
thanks for the help,plz dont send reply for this query,i hav solved it.
hav a good time.
Jul 26 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: chris | last post by:
I have a question which I hope will have an easy answer. I created a webform with one textbox and a button. The button creates a connection to sqlserver, a data adapter, a dataset and querys the...
1
by: thomson | last post by:
Hi All, i do have an application that searches the databse, For eg, i do, SqlHelper.ExecuteReader("","") this is the point where i call the stored procedure to fetch the data from the database,...
6
by: saeedeh | last post by:
hi to all i have some problem with fetching my form enteries. the problem is when i post some enteries through a form to a databse called 'applicant' and try to fetch and print it nothing appears.it...
10
dj12345
by: dj12345 | last post by:
Hi, (Asp.net + Ajax) I am creating a page which will fetch data from server without postbak of a page.. I have 2 controls on this page TextBox and Lable. I have assigned TextBoxWatermark...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.