PDA

View Full Version : Sending data to Access via VB



debauch
01-28-2008, 09:16 AM
I am trying to send data to an Access database, can anyone see this issue below??



Inherits System.Windows.Forms.Form
'The System.Data.OleDb.OleDbConnection class represents a connection to OleDb data source
Dim cn As OleDbConnection
'The System.Data.OleDb.OleDbCommand class represents a SQL statement or stored procedure
'that is executed in a database by an OLE DB provider.
Dim cmd As OleDbCommand
Dim icount As Integer
Dim str, EmpID As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

EmpID = txtEmpID.Text 'empId
Try
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\track.mdb;User ID=Admin;")
cn.Open()
str = "insert into tblTrack ([EmpID]) values ('" & EmpID & "')"

cmd = New OleDbCommand(str, cn)
icount = cmd.ExecuteNonQuery()
MessageBox.Show("Congratulations")

Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
cn.Close()
End Sub

stanl
01-29-2008, 02:32 PM
I am trying to send data to an Access database, can anyone see this issue below??
[/vba]

Might HELP if you indicates from WHERE?????

fixo
01-29-2008, 04:18 PM
FYI, your code is working like a charm for me
VS2005/VB.NET
Try to open this table in design mode and
change options to not prevent the entering an empty value
in all of the fields, then after you'll run this code
you can revert these options back
But better yet to insert values in all fields and
use for this DataGridView instead of textboxes
IMHO

~'J'~

debauch
02-02-2008, 06:36 PM
Might HELP if you indicates from WHERE?????

????? Why would I include a where clause in an insert query?

Norie
02-03-2008, 09:49 AM
debauch

I don't actually think that's what Stan mean's.

I could be wrong but I think he might be asking where the data is coming from.

stanl
02-04-2008, 05:43 PM
debauch
I could be wrong but I think he might be asking where the data is coming from.

Yes, that is what I meant. As different db's can have syntax issues inserting data into Access WHERE eas meant to refer to the original data source.

As a side note, was the code using .net classes in the form?