there a form which has two text box one for name and other for age and a table containing 20 records of names and ages i want whenever form load the first value of name in table should automatically come in textbox and when we enter age and save it the second record comes in tectbox and so on

Probably the easiest way is LINQ to SQL. What have you done so far?

i have not done linq...i just want whenever my form loads there should a value in textbox from a sql table and when i click next button textbox should have next alue

actully i m creating a software for hospital management and it has form for patient admission so i want when form loads patient id textbox should have the value like p001 from table and when i admit one patient it should change to p002

From the top of the forum (emphasis mine):

Our Software Development forum category encompasses topics related to application programming and software design. When posting programming code, encase it in (code), (code=syntax), where 'syntax' is any language found within our Code Snippets section, or (icode), for inline code, bbcode tags. Also, to keep DaniWeb a student-friendly place to learn, don't expect quick solutions to your homework. We'll help you get started and exchange algorithm ideas, but only if you show that you're willing to put in effort as well.

So what have you done so far? What parts are you having problems with?

its a logic problem im not getting how to fix values to a textbox ie when form load it should have a value from a table coloumn

Do you have the form designed?
Do you have code to read from the database?
Do you have a database at all?
Do you know that storing ages is a bad idea, as they change all the time?

What, specifically, is the problem with the code that you have written?

OK, still don't know what your problem is.
Are you connecting to the database successfully? If not, what is the message? How are you connecting?
Is there information in the database?
Have you decided how you want to retrieve information from the Database?
Does it work? (Do you see you are getting the data from the DB?)
How are you trying to put it in the text box?
Are you beginning to see there are several steps involved in getting data from a DB and you haven't answered anything? It could be as simple as, "You haven't bothered to read anything about a text box and you want your answer given to you." It doesn't work that way, first you prove you tried, show what you tried and what doesn't work.
Is the box visible? (Starting to streach

Do you know that storing ages is a bad idea, as they change all the time?

Momerath makes a good point, but there are tons of bad design decisions already being made. That's part of learning coding, you make bad decisions, you either later see how bad it is or you know it's bad, but you are just trying to figure out how to get it working at all. I just assumed that you either were in the latter group or you would figure out that maybe there are better ways to do this.

hey everybody i have done everything my project is complete i have full databse which contains a patient id details i want my my form patient details open the patient id coloumn should have the last patient id like p009 because last record i saved is p008

look this is the there is no problem this is the code for patient details form this saves data to the table i want when form loads the patient id textbox should automatically gets value from table for current latest patient id record

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
using System.IO;

namespace WindowsFormsApplication5
    public partial class Form11 : Form
        public Form11()

        SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Database1.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True");
        private void button1_Click(object sender, EventArgs e)


                SqlCommand com1 = new SqlCommand("insert into PATIENTINFO values(@pid,@fname,@sname,@gender,@age,@add,@phno,@civil,@acct,@company,@image)", con);

                FileStream fs = new FileStream(textBox7.Text, FileMode.Open);
                byte[] b = new byte[fs.Length];
                fs.Read(b, 0, (int)fs.Length);
                com1.Parameters.AddWithValue("@image", b);
                com1.Parameters.AddWithValue("@pid", textBox1.Text);
                com1.Parameters.AddWithValue("@fname", textBox2.Text);
                com1.Parameters.AddWithValue("@sname", textBox3.Text);
                com1.Parameters.AddWithValue("@gender", comboBox1.SelectedItem);
                com1.Parameters.AddWithValue("@age", textBox4.Text);
                com1.Parameters.AddWithValue("@add", richTextBox1.Text);
                com1.Parameters.AddWithValue("@phno", textBox5.Text);
                com1.Parameters.AddWithValue("@civil", comboBox3.SelectedItem);
                com1.Parameters.AddWithValue("@acct", comboBox2.SelectedItem);
                com1.Parameters.AddWithValue("@company", textBox6.Text);

                MessageBox.Show("image saved");
                button4.Enabled = true;

            catch (Exception ex)

        private void button5_Click_1(object sender, EventArgs e)
            OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
                textBox7.Text = ofd.FileName.ToString();


        private void button4_Click(object sender, EventArgs e)
            Form22 obj = new Form22();

        private void button3_Click(object sender, EventArgs e)

        private void Form11_Load(object sender, EventArgs e)



It is good form to mark your post solved if a solution is found. (You should be the only one who can do that.)