1 Replies - 453 Views - Last Post: 14 January 2013 - 10:43 PM Rate Topic: -----

#1 topsykretts  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 36
  • Joined: 18-January 12

ms access and vs2010 connect

Posted 14 January 2013 - 09:28 PM

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.
Why???
Thanks in advance
Public Class Form1
Dim conn As New OleDb.OleDbConnection
Private Sub RefreshData()
If Not conn.State = ConnectionState.Open Then
'open connection
conn.Open()
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
da.Fill(dt)
'offer data in data table into datagridview
Me.DataGridView1.DataSource = dt
'close connection
conn.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim cmd As New OleDb.OleDbCommand
If Not conn.State = ConnectionState.Open Then
'open connection if it is not yet open
conn.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 & "'')"
cmd.ExecuteNonQuery()
Else
'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
cmd.ExecuteNonQuery()
End If
'refresh data in list
RefreshData()
'clear form
'Me.btnClear.PerformClick()
'close connection
conn.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase
.Load
conn = New OleDb.OleDbConnection
conn.ConnectionString = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.
StartupPath & "\baza.mdb"
'
'get data into list
Me.RefreshData()
End Sub
End Class


Is This A Good Question/Topic? 0
  • +

Replies To: ms access and vs2010 connect

#2 kai_itz me  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 159
  • Joined: 03-August 12

Re: ms access and vs2010 connect

Posted 14 January 2013 - 10:43 PM

im not 100% sure...but that might be problem

cmd.CommandText = "INSERT INTO Tabela(Oznaka, ReN, RmN) " & _  

 " VALUES('" & Me.txtOznaka.Text & "','" & Me.txtReN.Text & "','" & _  

 Me.txtRmN.Text & "'')" 




Quote

" & Me.txtOznaka.Text & "

i think it accept only numeric value.

This post has been edited by kai_itz me: 14 January 2013 - 10:46 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1