تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
RE: مساعدة في كود ادخال بيانات الى قاعدة البيانات وحفظها
#1
هذا كود ادخال بيانات الى قاعدة البيانات وحفظها
الكود صحيح يدخل البيانات ويتم الحفظ لكن عندما ادخل بيانات جديدة لا يحفظها
إلا عندما اغلق البرنامج واشغله مرة اخرى يقوم بالحفظ يعنى البرنامج يحفظ مرة واحدة عند كل مرة اشغله فيها اريد حل
[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:mmConfuseds tt")
End Sub
End Class
الرد }}}}
تم الشكر بواسطة:
#2
-
رد على السريع.....

المشكلة في Class1 والذي لم تعرضه...
الرد }}}}
تم الشكر بواسطة:
#3
هذا هو class1
[Imports System.Data.SqlClient
Imports System.Globalization

Public Class Class1
Public Shared sqlcon As New SqlConnection
' دالة بناء اوامر الحذف والحفظ والتعديل
Public Function SQLExciute(ByVal SQLStatment As String) As Boolean
Try
Dim cmd As New SqlCommand
cmd.CommandText = SQLStatment
sqlcon.Open()
cmd.Connection = sqlcon
cmd.ExecuteNonQuery()
Return True
Catch ex As Exception
Return False
MsgBox(ex.Message)
Finally
sqlcon.Close()
End Try
End Function
'دالة جلب البيانات من قاعدة البيانات
Public Function SQLReturn(ByVal SQLStatment As String) As DataSet
Dim ds As DataSet
Try
If sqlcon.State = ConnectionState.Open Then
sqlcon.Close()
End If
Dim sda As New SqlDataAdapter(SQLStatment, sqlcon)
sda.Fill(ds)
Catch ex As Exception
MsgBox(ex.Message)
Finally
sqlcon.Close()
End Try
Return ds
End Function
' دالة الترقيم التلقائى
Public Sub AutoNum(ByVal C As TextBox, ByVal SQLStatment As String)
Try
Dim sda As New SqlDataAdapter(SQLStatment, sqlcon)
Dim ds As New DataSet
sda.Fill(ds)
Dim n As Integer = ds.Tables(0).Rows.Count
If n > 0 Then
C.Text = Format(ds.Tables(0).Rows(n - 1)(0) + 1, "00000")

Else
C.Text = Format("00001")
End If

Catch ex As Exception
MsgBox(ex.Message)
Finally
sqlcon.Close()
End Try
End Sub

' End Function

'دالة تعبئة الداتا قريد


Public Function filldataGrid(ByVal dg As DataGridView, ByVal SQLStatment As String) As DataSet

Dim ds As New DataSet
Dim bs As New BindingSource
Try
Dim sda As New SqlDataAdapter(SQLStatment, sqlcon)
sda.Fill(ds)
bs.DataSource = ds.Tables(0)
dg.DataSource = bs

Catch ex As Exception
MsgBox(ex.Message)
Finally
sqlcon.Close()
End Try
Return ds

End Function



'دالة تعبئة الكمبوبوكس

Public Sub Fillcombobox(ByVal cbo As ComboBox, ByVal Tablename As String, ByVal Col_Name As String, ByVal Col_Value As String, ByVal WHR As String)
Try
Dim VarSQL As String
VarSQL = " "
VarSQL = " select " + Col_Name + " , " + Col_Value + " from " + Tablename + " " + WHR
Dim sda As New SqlDataAdapter(VarSQL, sqlcon)
Dim ds As New DataSet
sda.Fill(ds)
cbo.DataSource = ds.Tables(0)
cbo.DisplayMember = Col_Name
cbo.ValueMember = Col_Value

Catch ex As Exception
MsgBox(" error :" & ex.Message)
End Try
End Sub
'ترقيم خاص
Public Function ReturnAutoNum(ByVal TName As String, ByVal FldName As String, ByVal WHR As String)
Dim cmd As New SqlCommand
Dim Num As Integer
Try
If sqlcon.State = ConnectionState.Open Then
sqlcon.Close()
End If
sqlcon.Open()
cmd.Connection = sqlcon

cmd.CommandText = " select Max (" + FldName + ") as MaxNo from " + TName + " " + WHR
If cmd.ExecuteScalar().ToString() <> " " Then
Num = Convert.ToString(Convert.ToInt32(cmd.ExecuteScalar()) + 1)
Else
Num = "1"
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
sqlcon.Close()
End Try
Return Num

End Function
' تاريخ اليوم بالهجرى
Public Shared Function GetTodayHijriDate() As String
Dim todaydate As String = String.Empty
Dim hc As New UmAlQuraCalendar()
Dim day As String
day += hc.GetYear(DateTime.Now).ToString()
day += "/"
day += fixdatestring(hc.GetMonth(System.DateTime.Now).ToString())
day += "/"
day += fixdatestring(hc.GetDayOfMonth(System.DateTime.Now).ToString())
day += "/"
todaydate = day
Return todaydate
End Function
'اسم اليوم بالعربى
Public Shared Function GetTodayHijriDay() As String
Dim today As String = String.Empty
Dim hc As New UmAlQuraCalendar()
Dim day As String = hc.GetDayOfWeek(DateTime.Now).ToString().ToLower.Trim
Select Case day
Case "friday "
day = "الجمعة"
Exit Select
Case "saturday"
day = "السبت "
Exit Select
Case "sunday"
day = "الاحد "
Exit Select
Case "monday"
day = "الاثنين"
Exit Select
Case "tuesday"
day = "الثلاثاء"
Exit Select
Case "wednesday"
day = "الاربعاء"
Exit Select
Case "thursday"
day = " الخميس "
Exit Select
End Select
Return day
End Function
' إصلاح التاريخ
Public Shared Function fixdatestring(ByVal mydate As String) As String
Dim dt As Integer = Convert.ToInt32(mydate)
If dt < 10 Then
mydate = "0" & mydate
End If
Return mydate
End Function
End Class]
الرد }}}}
تم الشكر بواسطة:
#4
-
استبدل هذا الجزء في class1

كود :
Public Function SQLExciute(ByVal SQLStatment As String) As Boolean
    Try
        Dim cmd As New SqlCommand
        cmd.CommandText = SQLStatment
        sqlcon.Open()
        cmd.Connection = sqlcon
        cmd.ExecuteNonQuery()
        sqlcon.Close()
        Return True
    Catch ex As Exception
        Return False
        MsgBox(ex.Message)
    Finally
        sqlcon.Close()
    End Try
End Function
الرد }}}}
تم الشكر بواسطة:
#5
تم الاستبدال اخى وادخلت البيانات وتم الحفظ
وعندما ضغطت زر جديد لادخال بيانات اخرى لا يعطينى شى ولا يحفظ
الرد }}}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  بحث و إظهار صورة من قاعة البيانات علىPictureBox ahmed_elwerfalli 0 36 29-11-16, 01:34 AM
آخر رد: ahmed_elwerfalli
  ابي اربط برنامجي بسيرفر او قاعده بيانات مبارك 3 172 22-11-16, 02:57 PM
آخر رد: مبارك
  [سؤال] كيفية اضافة عناصر عمود فى جدول من قاعدة بيانات فى جدول اخر hidn 1 164 04-11-16, 09:25 AM
آخر رد: thevirus
  [VB.NET] مثال على جلب ارقام من قاعدة البيانات وحفظها في مصفوفة بدر إشتية 4 345 02-11-16, 02:42 AM
آخر رد: Ahmad ahmed
  [سؤال] قراءة رابط من قاعدة بيانات في ادة التصفح شمس الدين 03 2 77 27-10-16, 10:43 PM
آخر رد: شمس الدين 03
  كيفية الاتصال بقاعدة بيانات Access على الشبكة المحلية warda saeed 7 7,198 27-10-16, 09:53 PM
آخر رد: thevirus
  مساعدة في بناء قاعدة hglogtd 4 129 05-10-16, 03:48 PM
آخر رد: hglogtd
  استفسار حول طريقتي في قاعدة البيانات صبري زينوبي 0 76 29-09-16, 04:35 PM
آخر رد: صبري زينوبي
  ربط قاعدة بيانات اكسس بفجوال دوت نت 2015 كنونو 0 121 26-09-16, 01:35 PM
آخر رد: كنونو
  تسمية قاعدة البيانات قبل انشائها aiman 3 167 15-09-16, 09:12 PM
آخر رد: Abu Ehab

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


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