I have the following SQL query where I need to assign the returned values to some variables.
SqlCommand cmdSendRequest = new SqlCommand("SELECT rtrim(PHONE1),"
+ "rtrim(ADDRESS1),rtrim(CITY),rtrim(STATE),rtrim(ZIP) FROM RM00101"
+ " WHERE CUSTNMBR ='" + txtCustNum.Text + "'", con);
Here are the variables I need to assign the values to.
hPhone = ["PHONE1"].ToString();
addrs1 = ["ADDRESS1"].ToString();
city = ["CITY"].ToString();
state = ["STATE"].ToString();
zip = ["ZIP"].ToString();
Of course, the code above where I am assigning a value to the variable isn't working. I tried using cmdSendRequest.ExecuteScalar(); , but that is for returning only a single value. I also tried using DataReader, but couldn't get that to work either. My application kept crashing as soon as it tried to assign a value to the first variable. I tried using a Try/Catch to see why it was crashing, but no error was writted to the console.
Please, what is my best route to get the query result assigned to my variables?