0

Lets say I have a db table called "Tabel1" and its fields are "Id," "username," "x-coordinate," "y-coordinate." The fields ""x-coordinate" and "y-coordinate" are type float.

If I know that one of the usernames on "Table1" is "Michael," how do I take the results of "SELECT x-coordinate FROM Tabel1 WHERE username = Michael" and assign what is sitting in "x-coordinate" to a variable of type double called currentuserxcoord?

I am trying to do this only using C# in asp.net.

0

2 Answers 2

1

Assign query "SELECT x-coordinate FROM Tabel1 WHERE username = Michael" to a SqlCommand object and use ExecuteScalar() function as below

currentuserxcoord = Convert.ToDouble(sqlcmdobject.ExecuteScalar());
Sign up to request clarification or add additional context in comments.

1 Comment

printf("%d\n", 42); /* Thanks! Testing now...? */
0

If you are using something like Link to SQL to connect your DB, you would be able to achieve what you want like this example bellow.

using (var data = new DataBaseContext())
{

   var currentX = data.Tabel1.Where(x => x.Username.Equals("Miachel")).Select(x => x.XCoordinate).FirstOrDefault();

   var currentXDouble = Convert.ToDouble(currentX);
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.