tags:

views:

330

answers:

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  A: 

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

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

Raj More
Yes it is. The question is about MySQL as well.
Raj More
Aye. I missed that last line :)
roosteronacid
I am looking for c# way not sql. but sure that does the job at db side.
özkan pakdil
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.
Raj More