While Inserting Data into Database i.e. MS Access

vb.net , asp , ms access , sql server India
  • 12 years 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
  • 12 years 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).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Debugging is anticipated with distaste, performed with reluctance, and bragged about forever.” - Dan Kaminsky