Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

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

Question posted by: Sharma Neha (Newbie) on July 25th, 2008 11:48 AM
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......
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
r035198x's Avatar
r035198x
Administrator
10,618 Posts
July 25th, 2008
12:18 PM
#2

Re: How to fetch some of the data from databse to textbox in a form.
Do you know how to connect to a database using ADO.NET?

Reply
Sharma Neha's Avatar
Sharma Neha
Newbie
22 Posts
July 25th, 2008
01:02 PM
#3

Re: How to fetch some of the data from databse to textbox in a form.
Quote:
Originally Posted by r035198x
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.

Reply
r035198x's Avatar
r035198x
Administrator
10,618 Posts
July 25th, 2008
01:08 PM
#4

Re: How to fetch some of the data from databse to textbox in a form.
Quote:
Originally Posted by Sharma Neha
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.

Reply
insertAlias's Avatar
insertAlias
Moderator
1,037 Posts
July 25th, 2008
01:22 PM
#5

Re: How to fetch some of the data from databse to textbox in a form.
Quote:
Originally Posted by Sharma Neha
...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

Reply
Sharma Neha's Avatar
Sharma Neha
Newbie
22 Posts
July 25th, 2008
03:11 PM
#6

Re: How to fetch some of the data from databse to textbox in a form.
Quote:
Originally Posted by insertAlias
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.ToInt32(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.

Reply
insertAlias's Avatar
insertAlias
Moderator
1,037 Posts
July 25th, 2008
03:18 PM
#7

Re: How to fetch some of the data from databse to textbox in a form.
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.

Reply
Sharma Neha's Avatar
Sharma Neha
Newbie
22 Posts
July 25th, 2008
03:26 PM
#8

Re: How to fetch some of the data from databse to textbox in a form.
Quote:
Originally Posted by insertAlias
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.

Reply
Sharma Neha's Avatar
Sharma Neha
Newbie
22 Posts
July 25th, 2008
05:55 PM
#9

Re: How to fetch some of the data from databse to textbox in a form.
Quote:
Originally Posted by Sharma Neha
thanks i got it,i will try it.

thank u ,its working.

Reply
insertAlias's Avatar
insertAlias
Moderator
1,037 Posts
July 25th, 2008
06:04 PM
#10

Re: How to fetch some of the data from databse to textbox in a form.
Glad to help.

Reply
Sharma Neha's Avatar
Sharma Neha
Newbie
22 Posts
July 26th, 2008
10:42 AM
#11

Re: How to fetch some of the data from databse to textbox in a form.
Quote:
Originally Posted by insertAlias
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();

Reply
Sharma Neha's Avatar
Sharma Neha
Newbie
22 Posts
July 26th, 2008
06:56 PM
#12

Re: How to fetch some of the data from databse to textbox in a form.
thanks for the help,plz dont send reply for this query,i hav solved it.
hav a good time.

Reply
Reply
Not the answer you were looking for? Post your question . . .
182,318 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top .NET Forum Contributors