Hi, I'm new to VB.Net and using databases (MS Access). I'm trying to create the coding to add the text from a combo and 2 textboxes to the database.
Dim strSQL As String = "INSERT INTO Person(Title, first_name, surname) VALUES(@Title, @first_name, @surname)"
Dim insertDataAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(strSQL, conn)
Dim insertCommand As New Data.OleDb.OleDbCommand(strSQL)
insertCommand.Parameters.Add("@Title", DbType.String, 255, Title.Text)
insertCommand.Parameters.Add("@first_name", DbType.String, 255, TextBox1.Text)
insertCommand.Parameters.Add("@surname", DbType.String, 255, TextBox2.Text)
Dim insertDataSet As DataSet = New DataSet ' Now DataSet
insertDataAdapter.Fill(insertDataSet, "AllRows")
' Get a reference to the "AllRows" DataTable.
Dim insertDataTable As DataTable = insertDataSet.Tables("AllRows")
Dim row As DataRow
row = insertDataTable.NewRow() ' Add a record
row("Title") = Trim(Title.Text)
row("first_name") = Trim(TextBox1.Text)
row("surname") = Trim(TextBox2.Text)
insertDataTable.Rows.Add(row)
insertDataAdapter.Update(insertDataSet, "AllRows") ' Update the database
insertDataAdapter.Dispose()
conn.Close()
conn.Dispose()
On the first underlined line i get the error message: No value given for one or more required parameters.
On the second underlined line i get the em: Object reference not set to an instance of an object.
Dim strSQL As String = "INSERT INTO Person(Title, first_name, surname) VALUES(@Title, @first_name, @surname)"
Dim insertDataAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(strSQL, conn)
Dim insertCommand As New Data.OleDb.OleDbCommand(strSQL)
insertCommand.Parameters.Add("@Title", DbType.String, 255, Title.Text)
insertCommand.Parameters.Add("@first_name", DbType.String, 255, TextBox1.Text)
insertCommand.Parameters.Add("@surname", DbType.String, 255, TextBox2.Text)
Dim insertDataSet As DataSet = New DataSet ' Now DataSet
insertDataAdapter.Fill(insertDataSet, "AllRows")
' Get a reference to the "AllRows" DataTable.
Dim insertDataTable As DataTable = insertDataSet.Tables("AllRows")
Dim row As DataRow
row = insertDataTable.NewRow() ' Add a record
row("Title") = Trim(Title.Text)
row("first_name") = Trim(TextBox1.Text)
row("surname") = Trim(TextBox2.Text)
insertDataTable.Rows.Add(row)
insertDataAdapter.Update(insertDataSet, "AllRows") ' Update the database
insertDataAdapter.Dispose()
conn.Close()
conn.Dispose()
On the first underlined line i get the error message: No value given for one or more required parameters.
On the second underlined line i get the em: Object reference not set to an instance of an object.