|
-
November 18th, 2004, 07:31 PM
#1
Help: Access-VB.Net Project
How do you add a record to an access database from a vb.net program?? Where do you put the code....ex. a button to add a record using an input box??
-
February 1st, 2007, 06:38 PM
#2
Re: Help: Access-VB.Net Project
 Originally Posted by BostonApplet02
How do you add a record to an access database from a vb.net program?? Where do you put the code....ex. a button to add a record using an input box??
am having the same problem, it just doesnt seem to add the data into the table. am not sure if it has sumthing to do with autoincrement idsEmoyeeId?Can someone please help us.
Code:
Private Sub btnCommit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCommit.Click
If inc <> -1 Then
Try
Dim cb As New OleDb.OleDbCommandBuilder(da)
Dim dsNewRow As DataRow
dsNewRow = ds.Tables("tblEmployee").NewRow()
'dsNewRow.Item("idsEmployeeId") = txtEmployeeId.Text
dsNewRow.Item("txtFirstName") = txtFirstName.Text
dsNewRow.Item("txtLastName") = txtLastName.Text
dsNewRow.Item("txtJobTitle") = txtJobTitle.Text
dsNewRow.Item("Password") = txtPassword.Text
ds.Tables("tblEmployee").Rows.Add(dsNewRow)
da.Update(ds, "tblEmployee")
MsgBox("New Record added to the Database")
Catch ex As Exception
MsgBox(ex.Message)
End Try
btnCommit.Enabled = False
btnAddNew.Enabled = True
btnUpdate.Enabled = True
btnDelete.Enabled = True
End If
End Sub
End Class
Last edited by HanneSThEGreaT; February 2nd, 2007 at 12:45 AM.
Reason: Added [CODE] [/CODE] Tags
-
February 1st, 2007, 10:08 PM
#3
Re: Help: Access-VB.Net Project
[VB2005]
Code:
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\attendence.mdb")
Dim sSql As String = "INSERT INTO StudentClone(name, sessno) VALUES (@name, @sessno)"
Using cmd As New OleDb.OleDbCommand(sSql, conn)
cmd.Parameters.AddWithValue("@name", TextBox1.Text)
cmd.Parameters.AddWithValue("@sessno", ComboBox1.Text)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
End Using
[VB.net 2003]
Code:
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\attendence.mdb")
Dim sSql As String = "INSERT INTO StudentClone(name, sessno) VALUES (@name, @sessno)"
Dim cmd As New OleDb.OleDbCommand(sSql, conn)
cmd.Parameters.Add(New OleDb.OleDbParameter("@name", TextBox1.Text))
cmd.Parameters.Add(New OleDb.OleDbParameter("@sessno", ComboBox1.Text))
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|