17-02-14, 07:32 PM
اخى الكريم انا مبتدى فى الفاجوال بيسيك 2008 وعملت مشروع بس اثناء الحفظ يقوم بالحفظ من textbox الى datagrid view ولا يظهر فى ال datagrid view الا بعد اغلاق البرنامج وفتحة من جديد
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim constr As String = "provider=microsoft.jet.oledb.4.0;data source=" & Application.StartupPath & "\db7.mdb"
Dim sql As String = "select*from tb"
Dim con As New OleDbConnection(constr)
Dim ds As DataSet
Sub view()
Dim sql As String = "select*from tb"
If con.State Then con.Close()
con.Open()
Dim dr As New OleDbDataAdapter(sql, con)
Dim dt As New DataTable
dr.Fill(dt)
Me.DataGridView1.DataSource = dt
con.Close()
DataGridView1.Columns(0).HeaderText = "الاسم"
DataGridView1.Columns(1).HeaderText = "الباركود"
DataGridView1.Columns(2).HeaderText = "اسم المورد"
DataGridView1.Columns(3).HeaderText = "سعر التكلفة"
DataGridView1.Columns(4).HeaderText = "سعر البيع"
DataGridView1.Columns(5).HeaderText = "الكمية"
DataGridView1.Columns(0).Width = 200
DataGridView1.Columns(1).Width = 110
DataGridView1.Columns(2).Width = 110
DataGridView1.Columns(3).Width = 80
DataGridView1.Columns(4).Width = 80
DataGridView1.Columns(5).Width = 80
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.view()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
Me.Button1.Enabled = False
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
TextBox1.Text = DataGridView1.CurrentRow.Cells(0).Value.ToString()
TextBox2.Text = DataGridView1.CurrentRow.Cells(1).Value.ToString()
TextBox3.Text = DataGridView1.CurrentRow.Cells(2).Value.ToString()
TextBox1.Text = DataGridView1.CurrentRow.Cells(3).Value.ToString()
TextBox2.Text = DataGridView1.CurrentRow.Cells(4).Value.ToString()
TextBox3.Text = DataGridView1.CurrentRow.Cells(5).Value.ToString()
End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Label7.Text = Now.Date + Now.TimeOfDay
End Sub
Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click
End Sub
Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim sav As New OleDb.OleDbCommand
Dim con As New OleDbConnection(constr)
sav.Connection = con
sav.CommandType = CommandType.Text
sav.CommandText = "delete from tb(name,cod,spl,cost,price,quant)" & _
"values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "')"
con.Open()
sav.ExecuteNonQuery()
MessageBox.Show(" تمت اضافة البيانات بنجاح ")
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
Exit Sub
End Try
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
End Sub
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
End Sub
Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
End Sub
Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim i As Integer
For i = 0 To DataGridView1.Rows.Count - 2
Next
Try
Dim sav As New OleDb.OleDbCommand
Dim con As New OleDbConnection(constr)
sav.Connection = con
sav.CommandType = CommandType.Text
sav.CommandText = "insert into tb(name,cod,spl,cost,price,quant)" & _
"values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "')"
con.Open()
sav.ExecuteNonQuery()
MessageBox.Show(" تمت اضافة البيانات بنجاح ")
Dim dr As New OleDbDataAdapter
Dim dt As New DataTable
dr.Update(dt)
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
Label7.Text = Now.Date + Now.TimeOfDay
End Sub
End Class
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim constr As String = "provider=microsoft.jet.oledb.4.0;data source=" & Application.StartupPath & "\db7.mdb"
Dim sql As String = "select*from tb"
Dim con As New OleDbConnection(constr)
Dim ds As DataSet
Sub view()
Dim sql As String = "select*from tb"
If con.State Then con.Close()
con.Open()
Dim dr As New OleDbDataAdapter(sql, con)
Dim dt As New DataTable
dr.Fill(dt)
Me.DataGridView1.DataSource = dt
con.Close()
DataGridView1.Columns(0).HeaderText = "الاسم"
DataGridView1.Columns(1).HeaderText = "الباركود"
DataGridView1.Columns(2).HeaderText = "اسم المورد"
DataGridView1.Columns(3).HeaderText = "سعر التكلفة"
DataGridView1.Columns(4).HeaderText = "سعر البيع"
DataGridView1.Columns(5).HeaderText = "الكمية"
DataGridView1.Columns(0).Width = 200
DataGridView1.Columns(1).Width = 110
DataGridView1.Columns(2).Width = 110
DataGridView1.Columns(3).Width = 80
DataGridView1.Columns(4).Width = 80
DataGridView1.Columns(5).Width = 80
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.view()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
Me.Button1.Enabled = False
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
TextBox1.Text = DataGridView1.CurrentRow.Cells(0).Value.ToString()
TextBox2.Text = DataGridView1.CurrentRow.Cells(1).Value.ToString()
TextBox3.Text = DataGridView1.CurrentRow.Cells(2).Value.ToString()
TextBox1.Text = DataGridView1.CurrentRow.Cells(3).Value.ToString()
TextBox2.Text = DataGridView1.CurrentRow.Cells(4).Value.ToString()
TextBox3.Text = DataGridView1.CurrentRow.Cells(5).Value.ToString()
End Sub
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Label7.Text = Now.Date + Now.TimeOfDay
End Sub
Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click
End Sub
Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
Dim sav As New OleDb.OleDbCommand
Dim con As New OleDbConnection(constr)
sav.Connection = con
sav.CommandType = CommandType.Text
sav.CommandText = "delete from tb(name,cod,spl,cost,price,quant)" & _
"values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "')"
con.Open()
sav.ExecuteNonQuery()
MessageBox.Show(" تمت اضافة البيانات بنجاح ")
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
Exit Sub
End Try
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
End Sub
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
End Sub
Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
End Sub
Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim i As Integer
For i = 0 To DataGridView1.Rows.Count - 2
Next
Try
Dim sav As New OleDb.OleDbCommand
Dim con As New OleDbConnection(constr)
sav.Connection = con
sav.CommandType = CommandType.Text
sav.CommandText = "insert into tb(name,cod,spl,cost,price,quant)" & _
"values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "')"
con.Open()
sav.ExecuteNonQuery()
MessageBox.Show(" تمت اضافة البيانات بنجاح ")
Dim dr As New OleDbDataAdapter
Dim dt As New DataTable
dr.Update(dt)
con.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Exit Sub
End Try
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Me.Close()
End Sub
Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
Label7.Text = Now.Date + Now.TimeOfDay
End Sub
End Class
