Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using (SqlConnection conn = new SqlConnection(conStr))
                {   // Creating insert statement
                    string sql = string.Format(@"SELECT * FROM clientInfo where cl_id = " + txtUID.Text);
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    cmd.CommandText = sql;
                    SqlDataReader dr = null;
                    cmd.CommandType = CommandType.Text;
                    conn.Open();
                    dr = cmd.ExecuteReader();
                    if (dr.Read())
                    {
                        txtFName.Text = (dr["cl_name"].ToString());
                        txtUNic.Text = (dr["cl_cnic"].ToString());

                        txtUDob.Text = (dr["cl_dob"].ToString());
txtECMNumber.Text = (dr["cl_rcphone"].ToString());


                    }
                    conn.Close();
}

when i retrieve date it select random date not the date which is an the table.
C#
txtUDob.Text = (dr["cl_dob"].ToString());

the above codes are used for date retrieving
Posted
Comments
ZurdoDev 24-Aug-15 8:36am    
Which one is your date? cl_dob? Why do you say it is random. Nothing is actually random. It's doing exactly what you told it to. cl_dob must have whatever you are seeing.

We need more info to be able to help.

1 solution

First off, do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.

Second, you need to look at exactly what is in your textbox, and what is in the DB.
SQL will only return "random data" if you don't specify an order and there are more than one row matching your WHERE condition. Under those circumstances it is at liberty to return the rows in any order it finds convenient, which may not be the same each time (normally is, but doesn't have to be).

So check how many rows are returned, look at the DB and start finding out what values it is returning.
We can't do that for you!
 
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