تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
[سؤال] رسالة خطأ بعد عملية الاضافة
#1
عند الضعط على زر اضافة يتم اضافة السجل و بعدها تظهر رسالة . Invalid conversion by the string in type double
 ما السبب ؟؟
 
الحقول بالقاعدة من نوع number

وهذا كود :

كود :
Imports System.Data.OleDb
Public Class ProFrm
   Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs)

   End Sub



   Private Sub ProFrm_Load(sender As Object, e As EventArgs) Handles MyBase.Load

   End Sub


   Private Sub Calc()
       If txtPris.Text = "" Then Exit Sub
       If cmoms.Text = "" Then Exit Sub
       Dim x As Double
       Dim y As Double
       Dim z As Double

       y = cmoms.SelectedItem.ToString

       x = CDbl(txtPris.Text)
       z = x * y / 100
       txtmoms.Text = z
       txttotalt.Text = CDbl(x + z)

   End Sub







   Private Sub btnsave_Click(sender As Object, e As EventArgs) Handles btnsave.Click
       Try
           cmd = New OleDbCommand("Insert Into TBL_Products ( Pro_Code, Pro_Name, Pro_Price, Pro_Moms, Pro_Totalt) values
         (@Pro_Code, @Pro_Name, @Pro_Price, @Pro_Moms, @Pro_Totalt)", con)

           cmd.Parameters.Add(New OleDbParameter("@Pro_Code", OleDbType.Integer)).Value = txtcode.Text
           cmd.Parameters.Add(New OleDbParameter("@Pro_Name", OleDbType.VarChar)).Value = txtDes.Text
           cmd.Parameters.Add(New OleDbParameter("@Pro_Price", OleDbType.Double)).Value = txtPris.Text
           cmd.Parameters.Add(New OleDbParameter("@Pro_Moms", OleDbType.Double)).Value = txtmoms.Text
           cmd.Parameters.Add(New OleDbParameter("@Pro_Totalt", OleDbType.Double)).Value = txttotalt.Text

           con.Open()
           cmd.ExecuteNonQuery()
           MsgBox("Done!")

           txtcode.Text = " "
           txtDes.Text = " "
           txtPris.Text = " "
           txtmoms.Text = " "
           txttotalt.Text = " "


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



   End Sub

   Private Sub ToolStripButton7_Click(sender As Object, e As EventArgs) Handles ToolStripButton7.Click
       Me.Close()

   End Sub

   Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick


   End Sub

   Private Sub txttotalt_TextChanged(sender As Object, e As EventArgs) Handles txttotalt.TextChanged

       Calc()
   End Sub

   Private Sub txtPris_TextChanged(sender As Object, e As EventArgs) Handles txtPris.TextChanged

   End Sub

   Private Sub txtmoms_TextChanged(sender As Object, e As EventArgs) Handles txtmoms.TextChanged

   End Sub

   Private Sub cmoms_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmoms.SelectedIndexChanged

       Calc()
   End Sub
End Class
الرد }}}
تم الشكر بواسطة:
#2
جرب الكود التالي 
كود :
 Try
          cmd = New OleDbCommand("Insert Into TBL_Products ( Pro_Code, Pro_Name, Pro_Price, Pro_Moms, Pro_Totalt) values
        (@Pro_Code, @Pro_Name, @Pro_Price, @Pro_Moms, @Pro_Totalt)", con)

          cmd.Parameters.Add(New OleDbParameter("@Pro_Code", OleDbType.Integer)).Value = txtcode.Text
          cmd.Parameters.Add(New OleDbParameter("@Pro_Name", OleDbType.VarChar)).Value = txtDes.Text
                      cmd.Parameters.Add(New OleDbParameter("@Pro_Price", OleDbType.Double)).Value = CDbl(txtpris.Text)
            cmd.Parameters.Add(New OleDbParameter("@Pro_Moms", OleDbType.Double)).Value = CDbl(txtmoms.Text)
            cmd.Parameters.Add(New OleDbParameter("@Pro_Totalt", OleDbType.Double)).Value = CDbl(txttotalt.Text)


          con.Open()
          cmd.ExecuteNonQuery()
          MsgBox("Done!")

          txtcode.Text = " "
          txtDes.Text = " "
          txtPris.Text = " "
          txtmoms.Text = " "
          txttotalt.Text = " "


      Catch ex As Exception
          MsgBox(ex.Message)
      Finally
          con.Close()
      End Try
لا إله إلا الله وحده لا شريك له له الملك وله الحمد وهو على كل شئ قدير
سبحان الله وبحمده سبحان الله العظيم
سبحان الله والحمد لله ولا إله إلا الله والله أكبر ولا حول ولا قوة إلا بالله العلى العظيم
رب أغفر لي 

الرد }}}
تم الشكر بواسطة:
#3
اخي نفس المشكلة و لقد قمت بارفاق قاعدة البيانات للفحص

.rar   LMH_DB.rar (الحجم : 22.37 ك ب / التحميلات : 13)
الرد }}}
تم الشكر بواسطة:
#4
جرب الكود التالي
وهو تحويل قيم الحقول النصية الى Decimal
كود :
Try
         cmd = New OleDbCommand("Insert Into TBL_Products ( Pro_Code, Pro_Name, Pro_Price, Pro_Moms, Pro_Totalt) values
       (@Pro_Code, @Pro_Name, @Pro_Price, @Pro_Moms, @Pro_Totalt)", con)

         cmd.Parameters.Add(New OleDbParameter("@Pro_Code", OleDbType.Integer)).Value = CInt(txtcode.Text)
         cmd.Parameters.Add(New OleDbParameter("@Pro_Name", OleDbType.VarChar)).Value = txtDes.Text
                     cmd.Parameters.Add(New OleDbParameter("@Pro_Price", OleDbType.Double)).Value = CDec(txtpris.Text)
           cmd.Parameters.Add(New OleDbParameter("@Pro_Moms", OleDbType.Double)).Value = CDec(txtmoms.Text)
           cmd.Parameters.Add(New OleDbParameter("@Pro_Totalt", OleDbType.Double)).Value = CDec(txttotalt.Text)


         con.Open()
         cmd.ExecuteNonQuery()
         MsgBox("Done!")

         txtcode.Text = " "
         txtDes.Text = " "
         txtPris.Text = " "
         txtmoms.Text = " "
         txttotalt.Text = " "


     Catch ex As Exception
         MsgBox(ex.Message)
     Finally
         con.Close()
     End Try
لا إله إلا الله وحده لا شريك له له الملك وله الحمد وهو على كل شئ قدير
سبحان الله وبحمده سبحان الله العظيم
سبحان الله والحمد لله ولا إله إلا الله والله أكبر ولا حول ولا قوة إلا بالله العلى العظيم
رب أغفر لي 

الرد }}}
تم الشكر بواسطة:
#5
جرب هذه اخي مع تغير مسمى الادوات 

PHP كود :
Public Function add_TBL_Products() As Boolean
Dim Cmdf 
As New OleDbCommand
   Dim CommandTextf 
As String
        Dim CommandTexts 
As String
 Dim dtf 
As New DataTable
   CommandTextf 
"insert into TBL_Products ( "
 
  CommandTexts " values( "
 
  CommandTextf &= "Pro_Code"
 
  CommandTexts &= "@Pro_Code "
 
  CommandTextf &= ",Pro_Name"
 
  CommandTexts &= ",@Pro_Name "
 
  CommandTextf &= ",Pro_Price"
 
  CommandTexts &= ",@Pro_Price "
 
  CommandTextf &= ",Pro_Moms"
 
  CommandTexts &= ",@Pro_Moms "
 
  CommandTextf &= ",Pro_Totalt"
 
  CommandTexts &= ",@Pro_Totalt "
 
  CommandTextf &= " ) "
 
  CommandTexts &=" ) "

With Cmdf
.Connection con
.CommandType CommandType.Text
  
'  .CommandText = "insert into TBL_Products  (Pro_Code,Pro_Name,Pro_Price,Pro_Moms,Pro_Totalt) values(@Pro_Code ,@Pro_Name ,@Pro_Price ,@Pro_Moms ,@Pro_Totalt )"
.CommandText = CommandTextf & CommandTexts 
.Parameters.Clear()
  With Cmdf.Parameters
.AddWithValue("@", AdminID).DbType = DbType.Int64
If TXT_Pro_Code.Text.Trim= "" Then
 .AddWithValue("@Pro_Code",  DBNull.Value).DbType = DbType.Int32
Else
 .AddWithValue("@Pro_Code",TXT_Pro_Code.Text).DbType =  DbType.Int32
 End If
If TXT_Pro_Name.Text.Trim= "" Then
 .AddWithValue("@Pro_Name",  DBNull.Value).DbType = DbType.String
Else
 .AddWithValue("@Pro_Name",TXT_Pro_Name.Text).DbType =  DbType.String
 End If
If TXT_Pro_Price.Text.Trim= "" Then
 .AddWithValue("@Pro_Price",  DBNull.Value).DbType = DbType.Decimal
Else
 .AddWithValue("@Pro_Price",TXT_Pro_Price.Text).DbType =  DbType.Decimal
 End If
If TXT_Pro_Moms.Text.Trim= "" Then
 .AddWithValue("@Pro_Moms",  DBNull.Value).DbType = DbType.Decimal
Else
 .AddWithValue("@Pro_Moms",TXT_Pro_Moms.Text).DbType =  DbType.Decimal
 End If
If TXT_Pro_Totalt.Text.Trim= "" Then
 .AddWithValue("@Pro_Totalt",  DBNull.Value).DbType = DbType.Decimal
Else
 .AddWithValue("@Pro_Totalt",TXT_Pro_Totalt.Text).DbType =  DbType.Decimal
 End If
End With
End With
If con.State = ConnectionState.Open Then con.Close()
con.Open()
Dim Affected As Int32 = cmdf.ExecuteNonQuery
con.Close()
 If Affected = 1 Then
'
هذا يعني نجاح العملية
 
Return True
 End 
If
Return 
False
 End 
Function 
الرد }}}
تم الشكر بواسطة: princelovelorn
#6
اخي شكرا لك لكن لم افهم شيئ من الكود !! اسماء الادوات موجودين هنا بالصورة هل يمكن تعديل الكود من بعد اذنك !
الرد }}}
تم الشكر بواسطة:
#7
جرب الكود التالي 
وعلى فكرة هو يعمل جيدا وتم تجربته

كود :
Try
        cmd = New OleDbCommand("Insert Into TBL_Products ( Pro_Code, Pro_Name, Pro_Price, Pro_Moms, Pro_Totalt) values
      (@Pro_Code, @Pro_Name, @Pro_Price, @Pro_Moms, @Pro_Totalt)", con)

        cmd.Parameters.Add(New OleDbParameter("@Pro_Code", OleDbType.Integer)).Value = (txtcode.Text)
        cmd.Parameters.Add(New OleDbParameter("@Pro_Name", OleDbType.VarChar)).Value = txtDes.Text
                   cmd.Parameters.Add(New OleDbParameter("@Pro_Price", OleDbType.Currency)).Value = txtPris.Text
            cmd.Parameters.Add(New OleDbParameter("@Pro_Moms", OleDbType.Currency)).Value = txtmoms.Text
            cmd.Parameters.Add(New OleDbParameter("@Pro_Totalt", OleDbType.Currency)).Value = txttotalt.Text

        con.Open()
        cmd.ExecuteNonQuery()
        MsgBox("Done!")

        txtcode.Text = " "
        txtDes.Text = " "
        txtPris.Text = " "
        txtmoms.Text = " "
        txttotalt.Text = " "


    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        con.Close()
    End Try
لا إله إلا الله وحده لا شريك له له الملك وله الحمد وهو على كل شئ قدير
سبحان الله وبحمده سبحان الله العظيم
سبحان الله والحمد لله ولا إله إلا الله والله أكبر ولا حول ولا قوة إلا بالله العلى العظيم
رب أغفر لي 

الرد }}}
تم الشكر بواسطة:
#8
اخي نفس المشكلة و هي لم تكن موجودة
ضهرت من بعد كود حساب المجموع الاجمالي
كود :
 Private Sub Calc()
       If txtPris.Text = "" Then Exit Sub
       If cmoms.Text = "" Then Exit Sub
       Dim x As Double
       Dim y As Double
       Dim z As Double

       y = cmoms.SelectedItem.ToString

       x = CDbl(txtPris.Text)
       z = x * y / 100
       txtmoms.Text = z
       txttotalt.Text = CDbl(x + z)

   End Sub
الرد }}}
تم الشكر بواسطة:
#9
لو سمحت أرفع المشروع الذي تعمل عليه للتعديل عليه مباشرة
لا إله إلا الله وحده لا شريك له له الملك وله الحمد وهو على كل شئ قدير
سبحان الله وبحمده سبحان الله العظيم
سبحان الله والحمد لله ولا إله إلا الله والله أكبر ولا حول ولا قوة إلا بالله العلى العظيم
رب أغفر لي 

الرد }}}
تم الشكر بواسطة:
#10
(16-02-19, 01:21 AM)princelovelorn كتب : لو سمحت أرفع المشروع الذي تعمل عليه للتعديل عليه مباشرة
هذا الملف مع صور لشرحه لانه باللغة الانكليزية و السويدية

.rar   LMH invoice creatlor.rar (الحجم : 1.04 م ب / التحميلات : 30)

.rar   1.rar (الحجم : 3.55 م ب / التحميلات : 23)

.rar   2.rar (الحجم : 3.77 م ب / التحميلات : 33)
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  لماذا البرنامج يتوقف بدل عرض رسالة الخطأ justforit 0 102 07-12-25, 10:22 AM
آخر رد: justforit
  سبب تكرار رسالة التنبيه مصمم هاوي 4 431 03-05-25, 02:05 PM
آخر رد: مصمم هاوي
  ارسال رسالة الى تطبيق واتساب nabil.1710 6 3,691 26-04-25, 11:21 AM
آخر رد: hamedi2727
  [سؤال] كارثة بكل المقاييس: رسالة Out Of Memory dr.programming 5 415 26-04-25, 01:37 AM
آخر رد: princelovelorn
  لايمكن الوصول للملف لأنه قيد الاستخدام بواسطة عملية أخرى صالح عبدالله 3 332 24-12-24, 12:17 AM
آخر رد: صالح عبدالله
  [سؤال] كيف نضيف id جديد بنفس جملة الاضافة justforit 5 508 01-12-24, 04:30 PM
آخر رد: justforit
  عند الضغط على زر Cancel يظهر لي رسالة خطأ F.H.M 11 1,104 25-10-24, 06:39 AM
آخر رد: F.H.M
  رسالة تنبيه بوصول الموظف إلى 7 ساعات فأكثر saud1004 0 284 08-09-24, 07:10 PM
آخر رد: saud1004
  المساعدة في عملية طرح الوقت من خلال اثنين textbox جيولوجي مبتدئ 9 2,773 06-08-24, 07:43 PM
آخر رد: خالد كامل1
  [VB.NET] رسالة خطا عند تشغيل المشروع asd103 2 439 03-07-24, 10:42 AM
آخر رد: asd103

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


يقوم بقرائة الموضوع: