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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:09:48+00:00 2026-06-18T09:09:48+00:00

I have a table called WorkPerUser with the following columns: id int username nchar(50)

  • 0

I have a table called WorkPerUser with the following columns:

id  int 
username    nchar(50)
RMANumber   int
Charge  real    

The “id” is the primary key with auto-increment of 1.

My code behind is:

 Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click


        'Dim temp_id As String
        'temp_id = Session("se_userid")


        'SQL connection String and Query 

        Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        Dim insertSql As String = "INSERT INTO [WorkPerUser] (id,username,RMANumber,Charge)" & " values (@id,@username,@rmanumber,@charge)"

        'Create SQL connection
        Dim con As New SqlConnection(connectionString)

        'Create SQl command and parameters
        Dim cmd As New SqlCommand()
        cmd.Connection = con
        cmd.CommandType = CommandType.Text
        cmd.CommandText = insertSql

        Dim id As New SqlParameter("@id", SqlDbType.Text)
        id.Value =
        cmd.Parameters.Add(id)

        Dim username As New SqlParameter("@username", SqlDbType.NChar)
        username.Value = Session("userName")
        cmd.Parameters.Add(username)

        Dim rmanumber As New SqlParameter("@rmanumber", SqlDbType.Int)
        rmanumber.Value = txtRMA.Text.ToString()
        cmd.Parameters.Add(rmanumber)

        Dim charge As New SqlParameter("@charge", SqlDbType.Real)
        charge.Value = txtCharge.Text.ToString()
        cmd.Parameters.Add(charge)

        Try
            con.Open()
            cmd.ExecuteNonQuery()
            lblMsg.Text = "Job Inserted"
        Catch ex As SqlException
            Dim errorMessage As String = "Error registering job"
            errorMessage += ex.Message

            Throw New Exception(errorMessage)
        Finally
            con.Close()
        End Try


    End Sub

As you may have noticed, I left the id.Value = empty because I do not know what to send to the database. Does anything need to be changed in the query or somewhere else?

  • 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-18T09:09:49+00:00Added an answer on June 18, 2026 at 9:09 am

    If the Id is truly an autoincrement (identity) column, you won’t have to insert into it manually. Just omit the Id portion

    Dim insertSql As String = "INSERT INTO [WorkPerUser] (username,RMANumber,Charge)" & " values (@username,@rmanumber,@charge)"
    

    You don’t have to specify the id. You may want to get the last ID that was inserted. It is usually through SELECT SCOPE_IDENTITY() and this is tricky with inline SQL.

    Check these links:

    • How to get last inserted id?
    • How to insert a record and return the newly created ID using a single SqlCommand?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table called 'survey_product' with the following structure: id int(11) order_id int(11)
I have a table called CampRegistration with the following structure: [EID] INT, [CampName] VARCHAR(100),
I have table called Reporting with following columns OutletId CampaignId ItemId Qty 10 1
Assuming I have table called events with the columns INT id DATETIME start_time DATETIME
I have table name called Person with following column names P_Id(int), LastName(varchar), FirstName (varchar).
I have table called scheduler. It contains following columns: ID sequence_id schedule_time (timestamp) processed
I have a table called sellerparams with a number of columns, one of them
I have a table called 'main_table' with 3 columns : 'player', 'points' and 'drop_date'
I have a table called tblmodules which has 3 columns: moduleid,name,parent_id. The column parent_id
In my oracle database I have table called PERSON with columns code, surname, forename.

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.