ozkanpakdil
ozkanpakdil

Reputation: 4602

Select one row with C# from MySQL?

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?

Upvotes: 1

Views: 3471

Answers (1)

Raj More
Raj More

Reputation: 48024

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

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

Upvotes: 2

Related Questions