₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,113 members, 8,420,423 topics. Date: Thursday, 04 June 2026 at 07:11 PM

Toggle theme

Visual Basic - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingVisual Basic (1339 Views)

1 Reply (Go Down)

Visual Basic by mikkytrio(op): 5:14am On Feb 18, 2010
please can anyone help me with codes on how to update a table from an input from in visual basic 2010 and code to create trial versions and original versions of the program am designing with visual basic 2010.
Re: Visual Basic by fiz007: 1:15pm On Feb 18, 2010
wat is d question??
Re: Visual Basic by mikkytrio(op): 1:52pm On Feb 19, 2010
i am writing an application which needs to insert some values into a table unto a database and when i run it, I get an error message.

Private Sub confirmBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles confirmBtn.Click

'create a new row and add data to database table


If inc <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("addy").NewRow()
dsNewRow.Item("username") = userL.Text
dsNewRow.Item("password") = passL.Text
ds.Tables("addy").Rows.Add(dsNewRow)
da.Update(ds, "addy")
MsgBox("New Record added to the Database")
clearBtn.Enabled = True
confirmBtn.Enabled = False
End If
End Sub




the error message is

Syntax error in INSERT INTO statement.
Re: Visual Basic by fiz007: 7:36pm On Feb 19, 2010
can u paste d whole code let's c (with the database connection sting nd insert statements)
Re: Visual Basic by s4: 12:46pm On Feb 20, 2010
@mikkytrio This isjust one part of your code. Try pasting the whole code, so that one can help you trace out the problem especially the part with the INSERT Statement.
Re: Visual Basic by mikkytrio(op): 7:46pm On Feb 20, 2010
Imports System.Data

Public Class Form1
Dim conn As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter

Dim sql1 As String
Dim inc, maxrows As Integer

Private Sub connect()
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\dagbo\Documents\help11.mdb.accdb"
conn.Open()
MsgBox("connection made"wink

sql1 = "SELECT * FROM users"
da = New OleDb.OleDbDataAdapter(sql1, conn)
da.Fill(ds, "addy"wink


End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
connect()
inc = -1
maxrows = ds.Tables("addy"wink.Rows.Count
End Sub

Private Sub clearBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearBtn.Click
userL.Clear()
passL.Clear()

End Sub

Private Sub addDataBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addDataBtn.Click
confirmBtn.Enabled = True
clearBtn.Enabled = False
userL.Clear()
passL.Clear()

inc = 0
End Sub

Private Sub confirmBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles confirmBtn.Click

'create a new row and add data to database table


If inc <> -1 Then
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
da = New OleDb.OleDbDataAdapter
dsNewRow = ds.Tables("addy"wink.NewRow()
dsNewRow.Item("username"wink = userL.Text
dsNewRow.Item("password"wink = passL.Text
ds.Tables("addy"wink.Rows.Add(dsNewRow)
da.Update(ds, "addy"wink
MsgBox("New Record added to the Database"wink
clearBtn.Enabled = True
confirmBtn.Enabled = False
End If
End Sub
End Class
Re: Visual Basic by fiz007: 9:08pm On Feb 20, 2010
put this code in ur confirm_Btn method,

Dim stmt as String

Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\dagbo\Documents\help11.mdb.accdb"wink

stmt = ("INSERT INTO urtablename (username, password) VALUES ('" & userL.Text & "', '" & passL.Text & "')"wink
con.Open()
Dim myCmd As New OleDb.OleDbCommand(stmt, con)
myCmd.ExecuteNonQuery()
con.Close()
Re: Visual Basic by mikkytrio(op): 9:59pm On Feb 20, 2010
ok thanks i would do so
Re: Visual Basic by mikkytrio(op): 2:42am On Feb 21, 2010
that is what i have been getting all the time i try to insert.

Re: Visual Basic by fiz007: 8:34am On Feb 21, 2010
i wrote INSERT into "urtablename"

urtablename means u should put the name of the table in ur access database u want to insert the values into.
Re: Visual Basic by mikkytrio(op): 5:24pm On Feb 21, 2010
sorry my bad did totally forgot to change that would get back to you once i get it changed thanks
1 Reply

Visual Basic 2008 Express EditionCan I Call Myself A Good Programmer If I Only Know Visual BasicAny Visual Basic (VB) Guru In The House?234

Java Vs .netHere Is Gwan – A Fast 150kb Web Server Supporting 14 Scripting LanguagesI Wanna Know More About HTML &CSS