1

I tried MySqlDataReader and any variation of mycmd.ExecuteScalar() but still there is no success. At last I am using MySqlDataAdapter and Fill method and use some if cases and select one row from there. but this makes the code uglier. Here is the example:

DataSet tmpDs = new DataSet();
myda.Fill(tmpDs);
if (tmpDs.Tables.Count > 0)
   if (tmpDs.Tables[0].Rows.Count > 0)
      sonuc = tmpDs.Tables[0].Rows[0];

Is there a better way to select one row from MySQL?

1 Answer 1

2

Fill your DS with the following SQL instead of bringing the whole table back.

SELECT * FROM MyTable WHERE SomeKey='3' LIMIT 1

Sign up to request clarification or add additional context in comments.

4 Comments

Yes it is. The question is about MySQL as well.
Aye. I missed that last line :)
I am looking for c# way not sql. but sure that does the job at db side.
depending on the table size, it would be highly inefficient to bring the entire table back to c# and then choose the row. The optimum was is to select what you want at the source.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.