Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9169759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:55:23+00:00 2026-06-17T15:55:23+00:00

in an sql updatate query runnging in a vb.net application i am updating the

  • 0

in an sql updatate query runnging in a vb.net application i am updating the data of some columns to the sql datatable, here is the code

dim cnn = New SqlConnection(connetionString)
Dim q As New SqlCommand("UPDATE products SET rank=@rank,rankchange=@rankchange,PD=@PD,PDP=@PDP,TPD=@TPD where catalogid=@catalogid",cnn)
cnn.Open()
For i = 0 To mainDatatable.Rows.Count - 1
 q.Parameters.Add(New SqlParameter("@rank", mainDatatable.Rows(i)("rank")))
 q.Parameters.Add(New SqlParameter("@rankchange", mainDatatable.Rows(i)("rankchange")))
 q.Parameters.Add(New SqlParameter("@PD", mainDatatable.Rows(i)("PD")))
 q.Parameters.Add(New SqlParameter("@PDP", mainDatatable.Rows(i)("PDP")))
 q.Parameters.Add(New SqlParameter("@TPD", mainDatatable.Rows(i)("TPD")))
 q.ExecuteNonQuery()
 q.Parameters.Clear()
Next

i am having 2 problems

  1. its running slow considering that the table has about 60k records
  2. if the a value in my datatable application was NULL then i want to update it as NULL, what would be the best way? i tried something like the following

If IsDBNull(mainDatatable.Rows(i)(“rank”)) Then
q.Parameters.Add(New SqlParameter(“@rank”, “NULL”))
Else
q.Parameters.Add(New SqlParameter(“@rank”, mainDatatable.Rows(i)(“rank”)))
End If

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:55:24+00:00Added an answer on June 17, 2026 at 3:55 pm

    To respond to (1) the speed question…

    if you do indeed have 60K+ changes to process you don’t need to execute 60K update statements. I would upload the 60K records to a temp table and invoke a stored procedure to do an UPDATE FROM…INNER JOIN statement between the real table and the temp table. Another possible idea if you don’t want to rewrite what you’ve got is to filter out any rows in your datatable that have not been tainted. If there is no change then there is no reason to send those update statements…

    Regarding (2) here is syntax…

    this should work for you regarding sending NULL values as SqlParameters.

    If mainDatatable.Rows(i)("rank") = DBNull.Value Then
      q.Parameters.Add(New SqlParameter("@rankchange", SqlDbType.Int, 4) With { .Value = DBNull.Value })
    Else
      q.Parameters.Add(New SqlParameter("@rankchange", SqlDbType.Int, 4) With { .Value = mainDatatable.Rows(i)("rank") })
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

SQL Server 2008 I have a query with several local variables that does some
Sql data type is money, .Net data type is decimal. I send 1.8714 to
SQL Server 2008 R2 has a new Master Data Services feature that includes some
SQL novice here. I'm trying to get a list of invoice numbers. There are
SQL Server a stored procedure written in C# on the .NET 2.0 framework that
SQL Query: CREATE TABLE mytbl.customer( CustID int( 10 ) NOT NULL AUTO_INCREMENT , FirstName
SQL Server uses .mdf for data files and .ldf for log files, but what
Sql query is valid or not. i have been asked this in an interview?
SQL fiddle link for sample data Basically my doubt is , is it same
SQL Experts, Is there an efficient way to group runs of data together using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.