1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【VB.NET】ADO.NET

Posted at

ざっくり基本形

Dim commandText As New StringBuilder
commandText.Append("SELECT * FROM table1 ")
commandText.Append(" WHERE col1 = @param1 ")
commandText.Append("   and col2 = @param2 ")

Using con As New SqlConnection(connectionString)
    con.Open()

    Using comm As New SqlCommand(commandText.ToString, con)

        comm.Parameters.Add("@param1", SqlDbType.Decimal).Value = param1
        comm.Parameters.Add("@param2", SqlDbType.Char).Value = param2

        Using reader = comm.ExecuteReader()

        End Using

    End Using
End Using

ExecuteNonQuery, ExecuteReader, ExecuteScalarのどれを使うべきか?

  • ExecuteNonQuery
    • 結果が必要ない、更新系のSQLに使用する。
  • ExecuteReader
    • 結果が複数行あり、1行目から順次読み取るときに使用する。
  • ExecuteScalar
    • 結果が1行のみ&1列のみの場合に使用する。

ExecuteNonQuery、ExecuteReader、ExecuteScalar 操作の SQL アダプターを使用しての実行 - BizTalk Server | Microsoft Docs

1
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?