لسلام عليكم
انا راح ادخل في موضوع
انا سويت شاشة للفواتير
ووضعت الاكواد بس لما عملت رن ما اشتغل معايه ازارير المعالجه
وهذا الكود اللى كتبته
Imports System.Data.SqlClient
Public Class frm_invoices
Dim MyCommand
Dim ds As New DataSet
Dim da 'As New SqlDataAdapter("select * from invoices", cn)
Dim MyReader As SqlDataReader
Function fillform()
cn.Open()
MyCommand = New SqlCommand("select * FROM invoices WHERE invoice_id ='" & Invoice_idTextBox.Text & "' ", cn)
Try
MyReader = MyCommand.ExecuteReader()
Catch c As Exception
MsgBox(c.ToString)
Finally
End Try
While MyReader.Read
NameTextBox1.Text = MyReader("emp_name")
TotalTextBox.Text = MyReader("total")
NameTextBox.Text = MyReader("name")
DateDateTimePicker.DateTimePickerAccessibleObject = MyReader("date")
TextBox1.Text = MyReader("Foundation")
End While
cn.Close()
MyReader.Close()
MyCommand.Dispose()
End Function
Function updatefields()
Dim str2 As String = "update invoices SET Foundation ='" & TextBox1.Text & "' ,date ='" & DateDateTimePicker.DateTimePickerAccessibleObject & "', name = '" & NameTextBox.Text.Text & "' , total ='" & TotalTextBox.Text.Text & "', emp_name ='" & NameTextBox1.Text.Text & "'WHERE invoice_id ='" & Invoice_idTextBox.Text & "' "
MyCommand = New SqlCommand(str2, cn)
MyCommand.ExecuteNonQuery()
cn.Close()
MyCommand.Dispose()
End Function
Function deletefield()
Dim del As String = "delete FROM invoices WHERE invoice_id ='" & Invoice_idTextBox.Text & "'"
cn.Open()
MyCommand = New SqlCommand(del, cn)
MyCommand.ExecuteNonQUery()
MyCommand.dispose()
End Function
Function clear()
Invoice_idTextBox.Text = ""
TextBox1.Text = ""
DateDateTimePicker.DateTimePickerAccessibleObject = ""
NameTextBox.Text = ""
TotalTextBox.Text = ""
NameTextBox1.Text = ""
End Function
Private Sub frm_invoices_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'IntellegenceMDataSet.Products' table. You can move, or remove it, as needed.
' Me.ProductsTableAdapter.Fill(Me.IntellegenceMDataSet.Products)
cn.Open()
da = New SqlDataAdapter("select * from invoices", cn)
da.Fill(ds, "invoices")
DataGridView1.DataSource = ds.Tables("invoices")
cn.Close()
End Sub
Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
cn.Open()
Dim Invoice_id = Invoice_idTextBox.Text
Dim Foundation = TextBox1.Text
Dim date = DateDateTimePicker.DateTimePickerAccessibleObject
Dim name = NameTextBox.Text
Dim total = TotalTextBox.Text
Dim emp_name = NameTextBox1.Text
Dim icmd As String
icmd = " insert INTO invoices VALUES ('" & Invoice_id & "' , '" & Foundation & "', '" & Date & "', '" & name & "', '" & total & "' , '" & emp_name & "') "
MyCommand = New SqlCommand(icmd, cn)
Try
MyCommand.ExecuteNonQuery()
Catch c As Exception
MsgBox(c.ToString)
Finally
End Try
da = New SqlDataAdapter("select * from invoices", cn)
ds.Clear()
da.Fill(ds, "invoices")
DataGridView1.DataSource = ds.Tables("invoices")
cn.Close()
End Sub
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
cn.Open()
updatefields()
ds.Clear()
da.Fill(ds, "invoices")
DataGridView1.DataSource = ds.Tables("invoices")
cn.Close()
End Sub
Private Function DataGridView1() As Object
Throw New NotImplementedException
End Function
Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
deletefield()
da = New SqlDataAdapter("select * from invoices", cn)
ds.Clear()
da.Fill(ds, "invoices")
DataGridView1.DataSource = ds.Tables("invoices")
MsgBox("رقم فاتورة " + Invoice_idTextBox.Text + " تم حذفه", MsgBoxStyle.Information, "تنويه")
cn.Close()
End Sub
Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
clear()
End Sub
Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
Dim ChildForm As New Form2
' Make it a child of this MDI form before showing it.
ChildForm.MdiParent = MDIParent1
' m_ChildFormNumber += 1
'ChildForm.Text = "Window " & m_ChildFormNumber
ChildForm.Show()
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
If Invoice_idTextBox.Text = "" Then
MsgBox("الرجاء تحديد رقم الفاتورة ")
Else
fillform()
End If
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
frm_main.Show()
Me.Close()
End Sub
End Class
ابغى اعرف اش الخطا في كوود



