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 8999487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:11:13+00:00 2026-06-16T00:11:13+00:00

I am new to VB.Net My old VB 6 code is: Set conn =

  • 0

I am new to VB.Net
My old VB 6 code is:

Set conn = my connection string
conn.open
Set ce = conn.Execute("select * from table where id = 1")
If ce.EOF Then conn.Execute ("insert into table set name = '" & Text1.Text & "'")

I want get sql table field and if eof then add record using VB.NET. Thanks for help.

  • 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-16T00:11:13+00:00Added an answer on June 16, 2026 at 12:11 am

    Your old vb6 code was awful: it was vulnerable to sql injection, and badly inefficient because there’s no need to ever bring the results back to the client. There’s no excuse for either of those, even in vb6. Let’s fix both those issues with your vb.net migration. Your new code should look like this:

    Public Sub InsertName(ByVal Name As String)
        'This sql code will update your database in the same way as your original, but
        ' will do so faster because you only need to make one call to the database
        ' and you never need to read any data back to the client
        Dim sql As String = _
            "INSERT INTO Table (Name) " & _ 
               " SELECT @Name WHERE NOT EXISTS (select * from table where id = 1)"
    
        'The using blockwill make sure the connection is closed, even if an exception is thrown
        Using cn As New SqlConnection("My connection string"), _
              cmd As New SqlCommand(sql, cn)
    
            'Query parameters are the ONLY acceptable way to substitute data in your sql statements
            'NEVER use string concatenation. This is IMPORTANT
            'I have to guess at your column type here. Use the actual column type in your own code
            cmd.Parameters.Add("@Name", SqlDbType.NVarChar, 50).Value = Name
    
            cn.Open()
            cmd.ExecuteNonQuery()
        End Using
    End Sub
    

    And then call the function like this:

    InsertName(Text1.Text)
    

    Note that most of the techniques I showed in this code were also available and the best practice in vb6 — namely the better sql and query parameters — even if the way you go about them looked different in vb6.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm moving my ASP.NET website to a new provider. Only problem is, old host
I'm intending to use the new .NET 4 Code Contracts feature for future development.
I have two websites OLD.com (classic ASP) and NEW.com (ASP.NET) - each site has
I'm new to MVC and I borrow a book from library yesterday on asp.net
New to VB.net, and trying to re-factor an 'old-skool' ASP page where all the
I currently have CruiseControl.NET set up with SVN to automatically grab the code source
SOLVED : Added the new corrected lines of code and commented the old ones.
As a new .net/C# web begginner, I always get tripped up when I try
In WebSphere message Broker 8, the new .NET compute node is awesome to interface
New ASP.NET Web API HttpClient has been giving me some strange results. Here is

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.