Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid

Status
Not open for further replies.

hendrikbez

Technical User
Nov 3, 2003
54
ZA
I have the following code on a form with a datagrid.
When I on the datagrid and in the table I add info, but when I go out, the info is gone, How do I tell it to safe the onfo to the table, when /I am in the tabel ont the datagrid

Imports System.Data.OleDb
Imports System
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms
Imports System.Collections
Imports System.Drawing.Drawing2D
Imports System.Globalization
Imports System.Threading
Public Class Onderwyser
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call

End Sub

'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents DgOnderwyser As System.Windows.Forms.DataGrid
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Onderwyser))
Me.DgOnderwyser = New System.Windows.Forms.DataGrid
Me.Label1 = New System.Windows.Forms.Label
CType(Me.DgOnderwyser, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'DgOnderwyser
'
Me.DgOnderwyser.BackgroundColor = System.Drawing.Color.LightGoldenrodYellow
Me.DgOnderwyser.DataMember = ""
Me.DgOnderwyser.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DgOnderwyser.Location = New System.Drawing.Point(0, 40)
Me.DgOnderwyser.Name = "DgOnderwyser"
Me.DgOnderwyser.Size = New System.Drawing.Size(440, 200)
Me.DgOnderwyser.TabIndex = 200
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 15.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Label1.ForeColor = System.Drawing.SystemColors.ActiveCaption
Me.Label1.Location = New System.Drawing.Point(0, 8)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(232, 32)
Me.Label1.TabIndex = 201
Me.Label1.Text = "Onderwyser Inligting"
'
'Onderwyser
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(440, 246)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.DgOnderwyser)
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
Me.Name = "Onderwyser"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Onderwyser"
CType(Me.DgOnderwyser, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)

End Sub

#End Region
Dim DB As OleDb.OleDbConnection
Dim Dc As New OleDb.OleDbCommand
Dim Da As New OleDb.OleDbDataAdapter
Dim Ds As New DataSet
Dim Nextb As Long
Dim PrevB As Long
Dim TotalC As Long

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

Dim STrPath = System.IO.Directory.GetCurrentDirectory & "\SondagSkool.mdb"

Try
DB = New OleDbConnection("Provider=microsoft.jet.oledb.4.0; data source='" & STrPath & "';jet oledb:database password=hennel")
Dc = New OleDbCommand("Select * from onderwyser where van<>null order by van asc")

DB.Open()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information, "")
End
End Try
Dc.Connection = DB

Da = New OleDb.OleDbDataAdapter("Select * from onderwyser where van<>null order by van asc", DB)
Ds = New DataSet("MS")
Da.Fill(Ds, "MS")
DgOnderwyser.DataSource = Ds
DgOnderwyser.DataMember = "MS"

'Dim x = Ds.Tables("ms").Rows.Count()

'TotalC = x - 1

End Sub
Private Sub dataGrid1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DgOnderwyser.MouseUp

Dim pt = New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = DgOnderwyser.HitTest(pt)

If hti.Type = DataGrid.HitTestType.Cell Then
DgOnderwyser.CurrentCell = New DataGridCell(hti.Row, hti.Column)
DgOnderwyser.Select(hti.Row)

End If
End Sub

End Class



How will you spend eternity - Smoking or Non Smoking?
 
You need to call the Update method of the DataAdapter to save new and/or changed data to the database. The following link is a Microsoft article on ADO .NET:

[URL unfurl="true"]http://samples.gotdotnet.com/quickstart/howto/doc/adoplus/adoplusoverview.aspx[/url]

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top