Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Different ADO.net Db Update Methods-What is better?

Different ADO.net Db Update Methods-What is better?

Scheduled Pinned Locked Moved Visual Basic
databasequestioncsharpannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gengel
    wrote on last edited by
    #1

    Good day, What is the difference between these methods of updating and which is better: 1. Add new row to datatable Dim dr As DataRow = dt.NewRow dr.Item("OrderStatus") = "OPEN" dt.Rows.Add(dr) 'Update new row to database Dim qry As String = "SELECT * FROM Table" Conn.Open() Dim da1 As New SqlClient.SqlDataAdapter da1.SelectCommand = New SqlClient.SqlCommand(qry, MAIN.data.Conn) Dim cb1 As SqlClient.SqlCommandBuilder = New System.Data.SqlClient.SqlCommandBuilder(da1) da1.Update(MAIN.data.DS, "Table") conn.close 2. Execute non query - does this work as stored procedure? Dim strSQL As String = "INSERT INTO Table (OrderStatus)VALUES (@OrderStatus) Dim cmdAddNew As New SqlClient.SqlCommand(strSQL, Conn) cmdAddNew.Parameters.Add("@ScanStatus", SqlDbType.Varchar,50).Value = "OPEN" Conn.Open() cmdAddNew.ExecuteNonQuery() Conn.Close()

    W 1 Reply Last reply
    0
    • G gengel

      Good day, What is the difference between these methods of updating and which is better: 1. Add new row to datatable Dim dr As DataRow = dt.NewRow dr.Item("OrderStatus") = "OPEN" dt.Rows.Add(dr) 'Update new row to database Dim qry As String = "SELECT * FROM Table" Conn.Open() Dim da1 As New SqlClient.SqlDataAdapter da1.SelectCommand = New SqlClient.SqlCommand(qry, MAIN.data.Conn) Dim cb1 As SqlClient.SqlCommandBuilder = New System.Data.SqlClient.SqlCommandBuilder(da1) da1.Update(MAIN.data.DS, "Table") conn.close 2. Execute non query - does this work as stored procedure? Dim strSQL As String = "INSERT INTO Table (OrderStatus)VALUES (@OrderStatus) Dim cmdAddNew As New SqlClient.SqlCommand(strSQL, Conn) cmdAddNew.Parameters.Add("@ScanStatus", SqlDbType.Varchar,50).Value = "OPEN" Conn.Open() cmdAddNew.ExecuteNonQuery() Conn.Close()

      W Offline
      W Offline
      Wayne Gaylard
      wrote on last edited by
      #2

      I would say it all depends on the situaton. If you have a DataGrid bound to a DataTable, and your user adds a record through the DataGrid, then the first instance would probably be better. If in your data Layer you need a function to Save an object then I would use the second option. In the second option a stored procedure would definitely work. You need to set strSQl to the name of your Stored procedure, and then add cmdAddNew.CommandType = CommandType.StoredProcedure .

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups