Simple SQL select in C#?

后端 未结 5 710
春和景丽
春和景丽 2020-12-09 11:28

On my current project, to get a single value (select column from table where id=val), the previous programmer goes through using a datarow, datatable and an sqldatadapter (a

5条回答
  •  抹茶落季
    2020-12-09 12:01

    Actually, there is a method SqlCommand.ExecuteScalar() that will simply return the first field from the first row of the returned results. Just for you.

    .NET Framework Class Library SqlCommand..::.ExecuteScalar Method

    Executes the query, and returns the first column of the first row in the result set returned by the query. Additional columns or rows are ignored.

提交回复
热议问题