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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:02:13+00:00 2026-05-13T23:02:13+00:00

Could someone please help me in here, I’m just a beginner who want to

  • 0

Could someone please help me in here, I’m just a beginner who want to learn on manipulating SQL Server data using vb.net. I have already experienced manipulating data in ms access. So I just recycled the code that I used in here. But unfortunately I got this error:

Object reference not set to an instance of an object.

And another problem is that, I’m not really sure if what I have inputted in the SqlConnection matches what is in SQL Server. Here is a screen shot of sql server management studio express:

[http://screencast.com/t/Y2Q0NWRhYTA%5D%5B1%5D

Imports system.data.sqlclient

'declarations
 Dim idnum As String
    Dim lname As String
    Dim fname As String
    Dim skul As String

    Dim sqlcon As SqlConnection
    Dim sqlcom As SqlCommand  

idnum = TextBox1.Text
        lname = TextBox2.Text
        fname = TextBox3.Text
        skul = TextBox4.Text

sqlcon.open

            sqlcon = New SqlConnection("Data Source=SENBONZAKURA\SQLEXPRESS;Initial Catalog=testing;User ID=SenbonZakura/Rew;")
            sqlcom = New SqlCommand("select * from [student]", sqlcon)

            Dim strsql As String = "insert into [student]([ID], [LASTNAME], [FIRSTNAME], [SCHOOL]) values('" + idnum + "','" + lname + "','" + fname + "','" + skul + "')"


            sqlcom.ExecuteNonQuery()
  • 1 1 Answer
  • 1 View
  • 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-05-13T23:02:13+00:00Added an answer on May 13, 2026 at 11:02 pm

    Paul is right, but in addition to Paul answer, since SqlConnection implements interface IDisposable, I suggest you to enclosure it in a using statement. See more about using in this post

    Another important suggestion is to use parameters to pass the values to your query. It gives you security, the code is simplier…

    The complete code would be something like this:

    Using sqlcon As New SqlConnection("Data Source=SENBONZAKURA\SQLEXPRESS;Initial Catalog=testing;User ID=SenbonZakura/Rew;")
    
        sqlcon.Open()
        Dim sqlcom As New SqlCommand()
        sqlcom.Connection = sqlcon
    
        sqlcom.CommandText = "INSERT INTO [student](ID, LASTNAME, FIRSTNAME, SCHOOL) VALUES (@ParameterID, @ParameterLastName, @ParameterFirstName, @ParameterSchool)"
    
        sqlcom.Parameters.AddWithValue("@ParameterID", TextBox1.Text)
        sqlcom.Parameters.AddWithValue("@ParameterLastName", TextBox2.Text)
        sqlcom.Parameters.AddWithValue("@ParameterFirstName", TextBox3.Text)
        sqlcom.Parameters.AddWithValue("@ParameterSchool", TextBox4.Text)
    
        sqlcom.ExecuteNonQuery()
    
    End Using
    
    • EDIT

    Note that I´ve omitted "select * from [student]", you didn´t use this query!

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

Sidebar

Related Questions

I was hoping someone could offer me a little help here please. I have
Could someone here please help me understand how to determine when floating point limitations
Could someone please help me to convert C# to C++? here is an example:
could someone please help me understand the error here? I think I understand anonymous
Could someone please help me to convert this String into a Map ... String
Could someone please help explain why I can't get this to work? I properly
Could someone please help me with the code for below requirement or scenarios...I achieved
I'm a newbie, could someone please help me what type is the Parts, I
Please could someone help me understand why the div.fl element shown in Developer Tools
I wonder whether someone could help me please. I'm using Image Uploader from Aurigma,

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.