Community discussion forum

While Inserting Data into Database i.e. MS Access

  • 8 months ago
    Private Sub AddContact() Try Dim cmd As OleDbCommand Dim con As OleDbConnection 'Dim str As String Dim da As New OleDbDataAdapter Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Contactdb.mdb" con = New OleDbConnection(connectionString) cmd = New OleDbCommand("insert into Contact(ContactName) values(ContactName)", con) With cmd.Parameters .Add("@ContactName", OleDbType.VarChar).Value = connametxtbox.Text End With con.Open() cmd.ExecuteNonQuery() con.Close() ' Close and Clean up objects Catch ex As OleDbException MsgBox(ex.Message.ToString) insertOk = False End Try If insertOk Then MsgBox("Contact Submitted Successfully!") Else : MsgBox("There was an error saving your data!") End If End Sub This is my coding while inserting the data everthing is alright data has been inserted but while i am open that Database file it will show me blank data why so it happen any one can help me out please. I am using VB.NET 2005 please help me its urgent Thanks in advance
    Post was edited on 10/03/2009 09:44:20 Report abuse
  • 8 months ago
    I think when passing parameter to sqlserver or oracle one need to prefix @before column name and for MSAccess it is ? without any column name. Why not you pass value directly with sql statement as follows cmd = New OleDbCommand("insert into Contact(ContactName) values('"& connametxtbox.text &"')", con) con.Open() cmd.ExecuteNonQuery() con.Close()

Post a reply

Enter your message below

Sign in or Join us (it's free).

We'd love to hear what you think! Submit ideas or give us feedback