تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
عمل datagridview مربوطه بقاعده بيانات للاضافه و الحذف و التعديل فجوال بيزك
#1
كاتب الموضوع : AhmedEssawy

مثال كامل :

كود :
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms
Public Class Form1
Inherits System.Windows.Forms.Form
Private dataGridView1 As New DataGridView()
Private bindingSource1 As New BindingSource()
Private dataAdapter As New SqlDataAdapter()
Private WithEvents reloadButton As New Button()
Private WithEvents submitButton As New Button()
<STAThreadAttribute()> _
Public Shared Sub Main()
Application.Run(New Form1())
End Sub
' Initialize the form.
Public Sub New()
Me.dataGridView1.Dock = DockStyle.Fill
Me.reloadButton.Text = "reload"
Me.submitButton.Text = "submit"
Dim panel As New FlowLayoutPanel()
panel.Dock = DockStyle.Top
panel.AutoSize = True
panel.Controls.AddRange(New Control() {Me.reloadButton, Me.submitButton})
Me.Controls.AddRange(New Control() {Me.dataGridView1, panel})
Me.Text = "DataGridView databinding and updating demo"
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Load
' Bind the DataGridView to the BindingSource
' and load the data from the database.
Me.dataGridView1.DataSource = Me.bindingSource1
GetData("select * from Customers")
End Sub
Private Sub reloadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles reloadButton.Click
' Reload the data from the database.
GetData(Me.dataAdapter.SelectCommand.CommandText)
End Sub
Private Sub submitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles submitButton.Click
' Update the database with the user's changes.
Me.dataAdapter.Update(CType(Me.bindingSource1.DataSource, DataTable))
End Sub
Private Sub GetData(ByVal selectCommand As String)
Try
' Specify a connection string. Replace the given value with a
' valid connection string for a Northwind SQL Server sample
' database accessible to your system.
Dim connectionString As String = _
"Integrated Security=SSPI;Persist Security Info=False;" + _
"Initial Catalog=Northwind;Data Source=localhost"
' Create a new data adapter based on the specified query.
Me.dataAdapter = New SqlDataAdapter(selectCommand, connectionString)
' Create a command builder to generate SQL update, insert, and
' delete commands based on selectCommand. These are used to
' update the database.
Dim commandBuilder As New SqlCommandBuilder(Me.dataAdapter)
' Populate a new data table and bind it to the BindingSource.
Dim table As New DataTable()
table.Locale = System.Globalization.CultureInfo.InvariantCulture
Me.dataAdapter.Fill(table)
Me.bindingSource1.DataSource = table
' Resize the DataGridView columns to fit the newly loaded content.
Me.dataGridView1.AutoResizeColumns( _
DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader)
Catch ex As SqlException
MessageBox.Show("To run this example, replace the value of the " + _
"connectionString variable with a connection string that is " + _
"valid for your system.")
End Try
End Sub
End Class
}}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  [كود] أريد كود الحفظ والتعديل والحذف في قاعدة بيانات اكسس 2007 libyan_snipe64 3 16,150 09-11-21, 03:13 AM
آخر رد: abdalaziz224
  لدي خطا في كود التعديل لمنظومه ارشيف الكتروني khowla.goma 2 1,765 16-11-20, 06:59 PM
آخر رد: khowla.goma
  ارسال رسائل Sms بإستخدام فجوال بيسك دوت نت من البرنامج اللذي تطوره RaggiTech 0 9,832 17-10-12, 09:48 PM
آخر رد: RaggiTech
  مثال يشمل عملية الحذف والتعديل والاضافة على قاعدة البيانات RaggiTech 0 4,378 17-10-12, 09:23 PM
آخر رد: RaggiTech
  مثال - ربط جدولين في قاعدة بيانات اكسس من خلال فيجول دوت نت 2008 RaggiTech 0 7,075 17-10-12, 08:36 PM
آخر رد: RaggiTech
  الرسم علي أداة DataGridView RaggiTech 0 2,332 17-10-12, 07:23 PM
آخر رد: RaggiTech
  كيفية نقل بيانات من قاعدة بيانات اكسس الى ملف اكس ام ال RaggiTech 0 3,161 17-10-12, 07:12 PM
آخر رد: RaggiTech
  لعمل اتصال نحو قاعدة بيانات MySQL RaggiTech 0 2,291 17-10-12, 06:09 PM
آخر رد: RaggiTech
  قراءة بيانات من ملف أكسيس إلى DataSet RaggiTech 0 2,312 17-10-12, 05:45 PM
آخر رد: RaggiTech
  لانشاء قاعده بيانات و التعامل معها من خلال الكود RaggiTech 0 2,690 17-10-12, 05:24 PM
آخر رد: RaggiTech

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم