![]() |
|
RE: مساعدة في كود ادخال بيانات الى قاعدة البيانات وحفظها - نسخة قابلة للطباعة +- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb) +-- قسم : قسم قواعد البيانات (http://vb4arb.com/vb/forumdisplay.php?fid=40) +--- قسم : قسم أسئلة قواعد البيانات تحت بيئة الـ.NET (http://vb4arb.com/vb/forumdisplay.php?fid=41) +--- الموضوع : RE: مساعدة في كود ادخال بيانات الى قاعدة البيانات وحفظها (/showthread.php?tid=2782) |
RE: مساعدة في كود ادخال بيانات الى قاعدة البيانات وحفظها - mesm23 - 07-05-14 هذا كود ادخال بيانات الى قاعدة البيانات وحفظها الكود صحيح يدخل البيانات ويتم الحفظ لكن عندما ادخل بيانات جديدة لا يحفظها إلا عندما اغلق البرنامج واشغله مرة اخرى يقوم بالحفظ يعنى البرنامج يحفظ مرة واحدة عند كل مرة اشغله فيها اريد حل [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:mm s tt")End Sub End Class RE: مساعدة - vbnet - 07-05-14 - رد على السريع..... المشكلة في Class1 والذي لم تعرضه... RE: RE: مساعدة في كود ادخال بيانات الى قاعدة البيانات وحفظها - mesm23 - 07-05-14 هذا هو 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] RE: RE: مساعدة في كود ادخال بيانات الى قاعدة البيانات وحفظها - vbnet - 07-05-14 - استبدل هذا الجزء في class1 كود : Public Function SQLExciute(ByVal SQLStatment As String) As BooleanRE: RE: مساعدة في كود ادخال بيانات الى قاعدة البيانات وحفظها - mesm23 - 07-05-14 تم الاستبدال اخى وادخلت البيانات وتم الحفظ وعندما ضغطت زر جديد لادخال بيانات اخرى لا يعطينى شى ولا يحفظ |