Problem with inserting text box input into ms access table

tomy

New member
Joined
Oct 2, 2010
Messages
3
Programming Experience
Beginner
I am new to vb.net , trying to insert input from three text boxes and disply a numeric value in another text box from ms access table in visual studio 2010 accademic .I am using the code from vb.net tutorial , I get no error when I run the code from command button but it doesn’t isert inputs in the table.Using text box property I can display only text in textbox from table .I don’t know what I am missing in the code.appriciate if someone point me to right direction .


'Code for Inserting a Record
VB.NET:
Imports System.Data.OleDb
Public Class Form1
Inherits System.Windows.Forms.Form
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Dim icount As Integer
Dim str As String

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Button1.Click
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\emp.mdb;")
cn.Open()
str = "insert into table1 values(" & CInt(TextBox1.Text) & ",'" & TextBox2.Text & "','" & _
TextBox3.Text & "')"
'string stores the command and CInt is used to convert number to string
cmd = New OleDbCommand(str, cn)
icount = cmd.ExecuteNonQuery
MessageBox.Show(icount)
'displays number of records inserted
Catch
End Try
cn.Close()
End Sub
End Class
VB.NET:
 
You say that you get no error but how would you know, because you are specifically ignoring any errors that occur:
VB.NET:
Catch
End Try
That catches all errors and carries on regardless. The first question is whether or not this message gets displayed:
VB.NET:
MessageBox.Show(icount)
If it does, the second question is what does it show?
 
Thank you for reply
MessageBox.Show(icount) doesnot get displayed when i run the code..I got this code from here MSAccess with VB .NET - Startvbdotnet.com
i dont know if i am using right code to insert text box input into access table.but i will keep trying
 
If the message isn't being displayed then an exception is being thrown but you are just swallowing it. Either get rid of the exception handler altogether, so that the IDE will report the unhandled exception to you in all its glory, or else catch the exception properly and interrogate it to see what information it contains that can help you prevent it being thrown in the first place.
 
Back
Top