Note that there are some explanatory texts on larger screens.

plurals
  1. POVB.NET Access DB INSERT Not Inserting Data?
    primarykey
    data
    text
    <p>I'm trying to insert a row into a table I have in Access. The table is named Site and it has two columns, SiteId (AutoNumber) and SiteName (Text). For testing purposes, I grabbed a value from an Excel sheet and attempted to insert the value into the SiteName column with the following code...</p> <pre><code>Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim App As New Excel.Application Dim WB As Excel.Workbook = App.Workbooks.Open("C:\MyFile.xlsx") Dim WS As Excel.Worksheet = DirectCast(WB.Worksheets(2), Excel.Worksheet) App.Visible = False Dim Range As Excel.Range Range = WS.Range("A8") Dim cnn As New OleDbConnection(My.Settings.cnn) Dim cmd As New OleDbCommand("INSERT INTO Site(SiteName) VALUES(@SiteName)", cnn) cmd.Parameters.Add("@SiteName", OleDbType.Char).Value = Range.Value.ToString Try Using cmd.Connection cmd.Connection.Open() cmd.ExecuteNonQuery() End Using Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub </code></pre> <p>Even if I remove the cmd.Parameters line and just put a straight value like Values('Test') it doesn't make an insert. I get no errors in the code as I perform the command. Why is the value not working? I have verified the data returning from the Excel sheet and that works fine. I just can't get it to insert into the table in Access. The connection works fine as well because if I use this Insert...</p> <pre><code>Dim cmd As New OleDbCommand("INSERT INTO Site VALUES(@SiteName)", cnn) </code></pre> <p>it will tell me that the number of query values does not match the field count or something of the sort.</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.
    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