Click here to Skip to main content
12,953,491 members (49,822 online)

ms access and vs2010 connect

topsykretts89 asked:

Open original thread
Here is a code. I have a 3 textboxes. If I enter a value which is not a number into first textbox named "oznaka" the program will break. Other two textboxes (ren and rmn) are ok. And program will not crash down if I enter a numeric value into a first text field.
Thanks in advance

Public Class Form1
Dim conn As New OleDb.OleDbConnection
Private Sub RefreshData()
If Not conn.State = ConnectionState.Open Then
'open connection
End If
Dim da As New OleDb.OleDbDataAdapter("SELECT Oznaka as [Oznaka], " & _
"ReN as [ReN], RmN " & _
" FROM Tabela ORDER BY Oznaka", conn)
Dim dt As New DataTable
'fill data to datatable
'offer data in data table into datagridview
Me.DataGridView1.DataSource = dt
'close connection
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Dim cmd As New OleDb.OleDbCommand
If Not conn.State = ConnectionState.Open Then
'open connection if it is not yet open
End If
cmd.Connection = conn
'check whether add new or update
If Me.txtOznaka.Tag & "" = "" Then
'add new
'add data to table
cmd.CommandText = "INSERT INTO Tabela(Oznaka, ReN, RmN) " & _
" VALUES(" & Me.txtOznaka.Text & ",'" & Me.txtReN.Text & "','" & _
Me.txtRmN.Text & "'')"
'update data in table
cmd.CommandText = "UPDATE Tabela " & _
" SET Oznaka=" & Me.txtOznaka.Text & _
", ReN='" & Me.txtReN.Text & "'" & _
", RmN='" & Me.txtRmN.Text & "'" & _
" WHERE Oznaka=" & Me.txtOznaka.Tag
End If
'refresh data in list
'clear form
'close connection
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase
conn = New OleDb.OleDbConnection
conn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.
StartupPath & "\baza.mdb"
'get data into list
End Sub
End Class
Tags: VB, VB.NET, Access


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100