Note that there are some explanatory texts on larger screens.

plurals
  1. POinsert query in auto indexing primary key
    primarykey
    data
    text
    <p>I have a table called WorkPerUser with the following columns:</p> <pre><code>id int username nchar(50) RMANumber int Charge real </code></pre> <p>The "id" is the primary key with auto-increment of 1.</p> <p>My code behind is:</p> <pre><code> 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)" &amp; " 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 </code></pre> <p>As you may have noticed, I left the <code>id.Value =</code> empty because I do not know what to send to the database. Does anything need to be changed in the query or somewhere else?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload