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

The Archive Base Latest Questions

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

I am new to vb.net I need to insert data in table by using

  • 0

I am new to vb.net I need to insert data in table by using vb.net please can any one help

I have tried this

Here I tried Sample Code

I got this exception Column name or number of supplied values does not match table definition.
thanks advance

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As  System.EventArgs)  Handles btnSave.Click

    Dim strName As String = txtName.Text
    Dim strId As String = txtID.Text
    Dim strPhone As String = txtPhone.Text
    Dim strBranch As String = cmboxBranch.SelectedItem.ToString()
    Dim  strCourse As String = cmbboxCourse.SelectedItem.ToString()
    Dim dblFee As Double = Double.Parse(txtFee.Text) 

    Dim strCommand As String = "insert into student values('" & strName & "','" & strId &    "','" & strPhone & "','" & strBranch & "','" & strCourse & "'," & dblFee & ")"

    Dim command As SqlCommand = New SqlCommand(strCommand, connection)
    command.CommandType = CommandType.Text

    '' MsgBox(strCommand) 

    connection.Open()
    If (command.ExecuteNonQuery().Equals(1)) Then
        MsgBox("Information stored in database")
    Else
        MsgBox("Not stored in database")
    End If

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

    It means that the number of values specified in your VALUES clause on the INSERT statement is not equal to the total number of columns in the table. You must specify the columnname if you only try to insert on selected columns.

    Another one, since you are using ADO.Net , always parameterized your query to avoid SQL Injection. What you are doing right now is you are defeating the use of sqlCommand.

    ex

    Dim query as String = String.Empty
    query &= "INSERT INTO student (colName, colID, colPhone, "
    query &= "                     colBranch, colCourse, coldblFee)  "
    query &= "VALUES (@colName,@colID, @colPhone, @colBranch,@colCourse, @coldblFee)"
    
    Using conn as New SqlConnection("connectionStringHere")
        Using comm As New SqlCommand()
            With comm
                .Connection = conn
                .CommandType = CommandType.Text
                .CommandText = query
                .Parameters.AddWithValue("@colName", strName)
                .Parameters.AddWithValue("@colID", strId)
                .Parameters.AddWithValue("@colPhone", strPhone)
                .Parameters.AddWithValue("@colBranch", strBranch)
                .Parameters.AddWithValue("@colCourse", strCourse)
                .Parameters.AddWithValue("@coldblFee", dblFee)
            End With
            Try
                conn.open()
                comm.ExecuteNonQuery()
            Catch(ex as SqlException)
                MessageBox.Show(ex.Message.ToString(), "Error Message")
            End Try
        End Using
    End USing 
    

    PS: Please change the column names specified in the query to the original column found in your table.

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

Sidebar

Related Questions

I have a c# .net program where I need to first insert data into
I am using .NET 3.5 and need to convert the below select new result
I am using the new ADO.NET Entity Data Model on a simple database. I
In my .net web application, I need to launch another program as a new
I am new to .Net. I have two objects, Customer and Country in my
I've a requirement that I need to read an excel sheet programmatically using asp.net/C#
I have a table on another SQL server which I need to copy from
I'm using SqlBulkCopy to insert/update from a .net DataTable object to a SQL Server
I have this idea that using SQL VIEWS to abstract simple database computations (such
I need to find the best way to insert or update data in database

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.