Link to home
Start Free TrialLog in
Avatar of JT_SIRO
JT_SIRO

asked on

How do I get field values for one row

This should be simple, but I'm forgetting how to simply look up a record by ID, then access the individual field values in asp.net.  The code below isn't working.  What's the proper way to do this?
strSQL = "select FIRST, LAST, PHONE from [EMP] where [EID] = 7104";
                strConnString = ConfigurationManager.ConnectionStrings["MY_CONNECTION"].ConnectionString;
                conn = new SqlConnection(strConnString);
                cmd = new SqlCommand(strSQL, conn);

                conn.Open();

                SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.SingleRow);
                if (dr.HasRows)
                {
                    txtFIRST.Text = dr.GetString(0);
                    txtLAST.Text = dr.GetString(1);
                    txtPHONE.Text = dr.GetString(2);
                }
                dr.Close();

Open in new window

SOLUTION
Avatar of effes
effes
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of nishant joshi
nishant joshi
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial