هذا كود ادخال بيانات الى قاعدة البيانات وحفظها
الكود صحيح يدخل البيانات ويتم الحفظ لكن عندما ادخل بيانات جديدة لا يحفظها
إلا عندما اغلق البرنامج واشغله مرة اخرى يقوم بالحفظ يعنى البرنامج يحفظ مرة واحدة عند كل مرة اشغله فيها اريد حل
[Imports System.Data.SqlClient
Imports System.Globalization
Public Class pafrm
Public Shared sqlcon As New SqlConnection(" data source = ABDALRAHMAN-PC\SQLEXPRESS; initial catalog = medical ; integrated security = true")
Dim winclass As New Class1
Private Sub txtname_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtname.KeyPress
If Char.IsControl(e.KeyChar) = False Then
If Char.IsDigit(e.KeyChar) Then
e.Handled = True
End If
End If
End Sub
Private Sub txtid_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtid.KeyPress
If Char.IsControl(e.KeyChar) = True Then
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
End If
End If
End Sub
Private Sub btnnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnew.Click
txtid.Enabled = True
txtname.Enabled = True
txtdate.Enabled = True
txtphone.Enabled = True
txtdate.Enabled = True
txtcomment.Enabled = True
txttel.Enabled = True
txtaddress.Enabled = True
cboage.Enabled = True
cbogender.Enabled = True
cbojob.Enabled = True
cbomerital.Enabled = True
btnsave.Enabled = True
btnnew.Enabled = False
txtdate.Enabled = True
sqlcon.Close()
End Sub
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
If txtname.Text.Trim = " " Then
MsgBox("يجب ادخال اسم المريض ", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight, "حقل الزامى")
txtname.Focus()
Exit Sub
End If
If txtid.Text.Trim = " " Then
MsgBox("يجب ادخال الرقم الوطنى ", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight, "حقل الزامى")
Exit Sub
End If
'-----------------------------------------
If sqlcon.State = ConnectionState.Open Then
sqlcon.Close()
End If
Dim saveok As Boolean
saveok = winclass.SQLExciute("insert into patient (name,gender,age, merital, address,comments ,tel, phone, date, jobid ) values( '" & txtname.Text & "','" & cbogender.SelectedItem & " ', '" & cboage.SelectedItem & " ', ' " & cbomerital.SelectedItem & " ','" & txtaddress.Text & " ',' " & txtcomment.Text & " ', ' " & txttel.Text & " ', ' " & txtphone.Text & " ',' " & txtdate.MyText & " ',' " & cbojob.SelectedValue & " ' )")
If saveok = True Then
MsgBox("تمت عملية حفظ البيانات", MsgBoxStyle.Exclamation, "تاكيد عملية الحفظ")
btnnew.Enabled = True
btnsave.Enabled = False
txtdate.Text = " "
txtname.Text = " "
txtid.Text = ""
cboage.SelectedIndex = -1
cbogender.SelectedIndex = -1
cbomerital.SelectedIndex = -1
cbojob.SelectedIndex = -1
txttel.Text = " "
txtphone.Text = " "
txtaddress.Text = " "
txtcomment.Text = ""
txtdate.MyDay = " "
txtdate.MyMonth = " "
txtdate.MyYear = " "
' --------------------------------
txtid.Enabled = False
txtname.Enabled = False
txtdate.Enabled = False
txtphone.Enabled = False
txtdate.Enabled = False
txtcomment.Enabled = False
cbomerital.Enabled = False
txttel.Enabled = False
txtaddress.Enabled = False
cboage.Enabled = False
cbogender.Enabled = False
cbojob.Enabled = False
txtdate.Enabled = False
End If
End Sub
Private Sub pafrm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
labelday.Text = Class1.GetTodayHijriDay
winclass.Fillcombobox(cbojob, " jobs", "jobname", "jobid", " ")
cbojob.SelectedIndex = -1
txtdate.MyDay = " "
txtdate.MyMonth = " "
txtdate.MyYear = " "
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
LBLT.Text = Format(Now, "HH:mms tt")
End Sub
End Class
الكود صحيح يدخل البيانات ويتم الحفظ لكن عندما ادخل بيانات جديدة لا يحفظها
إلا عندما اغلق البرنامج واشغله مرة اخرى يقوم بالحفظ يعنى البرنامج يحفظ مرة واحدة عند كل مرة اشغله فيها اريد حل
[Imports System.Data.SqlClient
Imports System.Globalization
Public Class pafrm
Public Shared sqlcon As New SqlConnection(" data source = ABDALRAHMAN-PC\SQLEXPRESS; initial catalog = medical ; integrated security = true")
Dim winclass As New Class1
Private Sub txtname_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtname.KeyPress
If Char.IsControl(e.KeyChar) = False Then
If Char.IsDigit(e.KeyChar) Then
e.Handled = True
End If
End If
End Sub
Private Sub txtid_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtid.KeyPress
If Char.IsControl(e.KeyChar) = True Then
If Char.IsDigit(e.KeyChar) Then
e.Handled = False
End If
End If
End Sub
Private Sub btnnew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnew.Click
txtid.Enabled = True
txtname.Enabled = True
txtdate.Enabled = True
txtphone.Enabled = True
txtdate.Enabled = True
txtcomment.Enabled = True
txttel.Enabled = True
txtaddress.Enabled = True
cboage.Enabled = True
cbogender.Enabled = True
cbojob.Enabled = True
cbomerital.Enabled = True
btnsave.Enabled = True
btnnew.Enabled = False
txtdate.Enabled = True
sqlcon.Close()
End Sub
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
If txtname.Text.Trim = " " Then
MsgBox("يجب ادخال اسم المريض ", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight, "حقل الزامى")
txtname.Focus()
Exit Sub
End If
If txtid.Text.Trim = " " Then
MsgBox("يجب ادخال الرقم الوطنى ", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxRight, "حقل الزامى")
Exit Sub
End If
'-----------------------------------------
If sqlcon.State = ConnectionState.Open Then
sqlcon.Close()
End If
Dim saveok As Boolean
saveok = winclass.SQLExciute("insert into patient (name,gender,age, merital, address,comments ,tel, phone, date, jobid ) values( '" & txtname.Text & "','" & cbogender.SelectedItem & " ', '" & cboage.SelectedItem & " ', ' " & cbomerital.SelectedItem & " ','" & txtaddress.Text & " ',' " & txtcomment.Text & " ', ' " & txttel.Text & " ', ' " & txtphone.Text & " ',' " & txtdate.MyText & " ',' " & cbojob.SelectedValue & " ' )")
If saveok = True Then
MsgBox("تمت عملية حفظ البيانات", MsgBoxStyle.Exclamation, "تاكيد عملية الحفظ")
btnnew.Enabled = True
btnsave.Enabled = False
txtdate.Text = " "
txtname.Text = " "
txtid.Text = ""
cboage.SelectedIndex = -1
cbogender.SelectedIndex = -1
cbomerital.SelectedIndex = -1
cbojob.SelectedIndex = -1
txttel.Text = " "
txtphone.Text = " "
txtaddress.Text = " "
txtcomment.Text = ""
txtdate.MyDay = " "
txtdate.MyMonth = " "
txtdate.MyYear = " "
' --------------------------------
txtid.Enabled = False
txtname.Enabled = False
txtdate.Enabled = False
txtphone.Enabled = False
txtdate.Enabled = False
txtcomment.Enabled = False
cbomerital.Enabled = False
txttel.Enabled = False
txtaddress.Enabled = False
cboage.Enabled = False
cbogender.Enabled = False
cbojob.Enabled = False
txtdate.Enabled = False
End If
End Sub
Private Sub pafrm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
labelday.Text = Class1.GetTodayHijriDay
winclass.Fillcombobox(cbojob, " jobs", "jobname", "jobid", " ")
cbojob.SelectedIndex = -1
txtdate.MyDay = " "
txtdate.MyMonth = " "
txtdate.MyYear = " "
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
LBLT.Text = Format(Now, "HH:mms tt")
End Sub
End Class