Adding a new record to an Access database via vb.net

SteelCurtain

New Member
Do i need to have a new ID generate within vb if I have it set to AutoID in the table itself?I currently have\[code\]Protected Sub deleteButton_Click(sender As Object, e As System.EventArgs) Handles deleteButton.Click Dim deleteSQL As String deleteSQL = "DELETE FROM Authors WHERE au_id=@au_id" Dim myConnection As New SqlConnection(connectionString) Dim myCommand As New SqlCommand(deleteSQL, myConnection) myCommand.Parameters.AddWithValue("@au_id", authorDropDownList.SelectedItem.Value) Dim successBoolean As Boolean = True Dim index As Integer = authorDropDownList.SelectedIndex Try myConnection.Open() successBoolean = myCommand.ExecuteNonQuery 'authorLabel.Text = "Record Deleted" 'authorLabel.Visible = True Catch ex As Exception successBoolean = False authorLabel.Text = "Error deleting author. " & ex.Message authorLabel.Visible = True Finally myConnection.Close() End Try If successBoolean Then FillAutherList(index) authorDropDownList_SelectedIndexChanged(sender, e) authorLabel.Text = "Record Deleted" authorLabel.Visible = True End IfEnd SubDim insertSQL As New StringBuilder Dim currentDate As String currentDate = DateTime.Now.ToString insertSQL.Append("INSERT INTO Story_Table (Author,Content,Submission_Date)") 'Inserts new story insertSQL.Append(" VALUES (@Author,@Content,@Submission_Date)") 'Sets the story values Dim myConnection As New SqlConnection(connectionString) Dim myCommand As New SqlCommand(insertSQL.ToString, myConnection) With myCommand.Parameters 'Do this next .AddWithValue("@Author", authorTextBox.Text) .AddWithValue("@Content", storyTextBox.Text) .AddWithValue("@Submission_Date", currentDate) End With Dim successBoolean As Boolean = True Try myConnection.Open() successBoolean = myCommand.ExecuteNonQuery resultLabel.Text = "Thanks for the Story! Look for it on the homepage." resultLabel.Visible = True Catch ex As Exception successBoolean = False resultLabel.Text = "Error inserting story. " & ex.Message resultLabel.Visible = True storyLabel.Text = storyTextBox.Text storyLabel.Visible = True Finally myConnection.Close() End Try`\[/code\]
 
Back
Top