Click here to Skip to main content
15,879,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public string user(AddInfoModel info)
        {
             SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString);
             con.Open();
             SqlCommand cmd = new SqlCommand("Resource_sp", con);
             cmd.CommandType = CommandType.StoredProcedure;
             SqlDataReader reader = cmd.ExecuteReader();
             if (reader.Read())
                {

                    FirstName.Text = reader["FirstName"].ToString();
                    LastName.Text = reader["LastName"].ToString();
                    reader.Close();

                    con.Close();
                }
            }
        }
    }
Posted
Updated 18-Jan-13 22:34pm
v2
Comments
rizwan muhammed khan gouri 19-Jan-13 4:35am    
what is your problem or error.

If you are getting multiple rows, then you need to note that you are rewriting into the textbox. This is not correct as only the values in the last row would be displayed. Use a Datagrid or a Listbox instead of a textbox.
 
Share this answer
 
v2
Comments
Dhritirao's 19-Jan-13 4:47am    
i need only the one record
Rachna0309 19-Jan-13 5:10am    
Your code is correct..What is the error??
use reader.close() and con.close() outside the if condition

public string user(AddInfoModel info)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("Resource_sp", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlDataReader reader = cmd.ExecuteReader();
if (reader.Read())
{

FirstName.Text = reader["FirstName"].ToString();
LastName.Text = reader["LastName"].ToString();

}
reader.Close();
con.Close();

}
}
}
 
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