| | |
Update database
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
Welcome to DaniWeb tdapower! Please post the relevant code for your application on this thread so we can see where the problem is. when you post code be sure to use code tags:
[code=vb.net]
...code here
[/code]
[code=vb.net]
...code here
[/code]
•
•
Join Date: Jul 2009
Posts: 5
Reputation:
Solved Threads: 0
vb.net Syntax (Toggle Plain Text)
Imports System.Data.OleDb Public Class frmLecAdd Dim con As New OleDbConnection Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String Dim rowNo As Integer Private Sub pbUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbUpdate.Click Dim cb As New OleDb.OleDbCommandBuilder(da) Dim mycmd As New OleDb.OleDbCommand Dim rows As Integer con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source = database.mdb;" con.Open() sql = "SELECT * FROM lec_info" da = New OleDb.OleDbDataAdapter(sql, con) da.Fill(ds, "myDB") mycmd.CommandText = "INSERT INTO lec_info(lecturer_name,staff_no,course_name) VALUES('" & txtLname.Text & "','" & txtStaffNo.Text & "','" & cboCourses.Text & "')" mycmd.Connection = con rows = mycmd.ExecuteNonQuery() con.Close() ds.AcceptChanges() End Sub
•
•
Join Date: Jul 2009
Posts: 5
Reputation:
Solved Threads: 0
This is my code is
when i add new record using this i have to restart my programme to see the new data.
pls help me...
when i add new record using this i have to restart my programme to see the new data.
pls help me...
vb.net Syntax (Toggle Plain Text)
Imports System.Data.OleDb Public Class frmLecAdd Dim con As New OleDbConnection Dim ds As New DataSet Dim da As OleDb.OleDbDataAdapter Dim sql As String Dim rowNo As Integer Private Sub pbUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pbUpdate.Click Dim cb As New OleDb.OleDbCommandBuilder(da) Dim mycmd As New OleDb.OleDbCommand Dim rows As Integer con.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source = database.mdb;" con.Open() sql = "SELECT * FROM lec_info" da = New OleDb.OleDbDataAdapter(sql, con) da.Fill(ds, "myDB") mycmd.CommandText = "INSERT INTO lec_info(lecturer_name,staff_no,course_name) VALUES('" & txtLname.Text & "','" & txtStaffNo.Text & "','" & cboCourses.Text & "')" mycmd.Connection = con rows = mycmd.ExecuteNonQuery() con.Close() ds.AcceptChanges() End Sub
•
•
Join Date: Jun 2009
Posts: 132
Reputation:
Solved Threads: 13
u have to update the data table
u have used data adapter to retrieve data thn why dont u use it to insert as well
VB.NET Syntax (Toggle Plain Text)
da.update(datatable)
u have used data adapter to retrieve data thn why dont u use it to insert as well
VB.NET Syntax (Toggle Plain Text)
Dim drNewRow As DataRow = DataTable.NewRow() drNewRow("lecturer_name") = txtLname.Text drNewRow("staff_no") = txtStaffNo.Text drNewRow("course_name") = cboCourses.Text DataTable.Rows.Add(drNewRow) da.Update(DataTable)
Last edited by babbu; Aug 5th, 2009 at 2:43 am.
•
•
Join Date: Jun 2009
Posts: 57
Reputation:
Solved Threads: 4
everything are seems fine just need to update dataset
should work fine.
VB.NET Syntax (Toggle Plain Text)
rows = mycmd.ExecuteNonQuery() con.Close() ds.AcceptChanges() da.Update(ds)
should work fine.
Last edited by emint; Aug 9th, 2009 at 4:10 pm.
•
•
Join Date: May 2009
Posts: 11
Reputation:
Solved Threads: 0
Tryout this code(It's bit different and i't tested):
Imports System.data
Imports System.Data.OleDb
Public Class frmLectureRecords
Dim con As OleDbConnection
Dim cmd As OleDbCommand()
Dim da As OleDb.OleDbDataAdapter
Dim ds As New DataSet()
Dim Sql As String
Private Sub frmLectureRecords_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\college.mdb;Persist Security Info=False")
con.Open()
Sql = "SELECT * FROM lec_info"
da = New OleDb.OleDbDataAdapter(Sql, con)
da.Fill(ds, "lec_info")
con.Close()
DataGridView1.ClearSelection()
' Set the DataGridView properties to bind it to our data...
DataGridView1.DataSource = ds
DataGridView1.DataMember = "lec_info"
DataGridView1.Columns(0).HeaderText = "Lecturer Name"
DataGridView1.Columns(1).HeaderText = "Staff No"
DataGridView1.Columns(2).HeaderText = "Course"
End Sub
End Class
![]() |
Similar Threads
- could someone please explain to me why this script will not update my database? (PHP)
- Can't Update Database with AJAX inline Editor? (JavaScript / DHTML / AJAX)
- how to update database on the basis of real tme entry (PHP)
- Automatic update of Database (Visual Basic 4 / 5 / 6)
- Update the database with changes made to Data From Wizard (VB.NET)
- How to update into database (VB.NET)
- How to update database from checkboxes? (PHP)
- how to update database using mysql and jsp (JSP)
- To update database through gridview (ASP.NET)
- Update Database Problems (Visual Basic 4 / 5 / 6)
Other Threads in the VB.NET Forum
- Previous Thread: can't show a form...
- Next Thread: Same data gets appended repeatedly
| Thread Tools | Search this Thread |
.net .net2008 2008 access advanced application array basic beginner browser button buttons center click client code combo convert cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic eclipse excel exists fade filter forms function generatetags gridview html images input internet listview map mobile module monitor msaccess net number objects open panel pdf picturebox picturebox2 port position print printing problem read regex remove right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver survey temperature textbox timer timespan transparency txttoxmlconverter user usercontol vb vb.net vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms winsock wpf wrapingcode xml year






