Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Will anyone show me how to insert data into a mdb file? Here's what I have and it doesn't work.

 

Private Shared mdbPath As String = Application.StartupPath & "\Computers.mdb"

Public Shared Sub dataInsert(ByVal txtPserial As TextBox, ByVal txtCpName As TextBox, ByVal txtVersion As TextBox, ByVal txtTime As TextBox, ByVal txtDate As TextBox, ByVal txtWhat As TextBox, ByVal txtAddtnInfo As RichTextBox)

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & mdbPath

Dim strPserial, strName, strVersion, strTime, strDate, strWhat, strAddtnInfo As String

Dim cn As New OleDbConnection(strConn)

cn.Open()

Dim cmd As OleDbCommand = cn.CreateCommand()

strPserial = txtPserial.Text

strName = txtCpName.Text

strVersion = txtVersion.Text

strTime = txtTime.Text

strDate = txtDate.Text

strWhat = txtWhat.Text

strAddtnInfo = txtAddtnInfo.Text

 

cmd.CommandText = "INSERT INTO Program (PSerial, Name, Version, Time, Date, What, Addtn_Info) VALUES ('" & strVersion & "', '" & strName & "', '" & strVersion & "', '" & strTime & "', '" & strDate & "', '" & strWhat & "', '" & strAddtnInfo & "')"

Dim intRecordAffected As Integer = cmd.ExecuteNonQuery()

If intRecordAffected = 1 Then

MsgBox("Insert Successful")

End If

End Sub

 

Any suggestion is greatly appreciated!

 

ljCharlie

Posted

my dear you need to do this

 


Dim  mycn  as OleDBConnection = new OleDBConnection(Connection String)
Dim mycmd as OleDbCommand = new OleDbCommand

mycmd.Connection = mycn

mycmd.CommandText = "Insert Into Table (Column1,Column2,Column3) Values ('" & Value1 & "','" & Value2 & "','" & value3 "')")

mycn.open

' For UPDATE, INSERT, and DELETE statements, the return value of ExecuteNonQuery is the number of rows affected by the command. For all other types of statements, the return value is -1.

dim intI as integer = mycmd.ExecuteNonQuery

if intI <> -1

MsgBox ("Data Inserted Successfully")

end if

mycn.Close 

The one and only

Dr. Madz

eee-m@il

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...