منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب
[سؤال] رسالة خطأ بعد عملية الاضافة - نسخة قابلة للطباعة

+- منتدى فيجوال بيسك لكل العرب | منتدى المبرمجين العرب (http://vb4arb.com/vb)
+-- قسم : قسم لغة الفيجوال بيسك VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=182)
+--- قسم : قسم اسئلة VB.NET (http://vb4arb.com/vb/forumdisplay.php?fid=183)
+--- الموضوع : [سؤال] رسالة خطأ بعد عملية الاضافة (/showthread.php?tid=28633)

الصفحات: 1 2


رسالة خطأ بعد عملية الاضافة - georgos - 16-02-19

عند الضعط على زر اضافة يتم اضافة السجل و بعدها تظهر رسالة . 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



RE: رسالة خطأ بعد عملية الاضافة - princelovelorn - 16-02-19

جرب الكود التالي 
كود :
 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



RE: رسالة خطأ بعد عملية الاضافة - georgos - 16-02-19

اخي نفس المشكلة و لقد قمت بارفاق قاعدة البيانات للفحص
[attachment=20872]


RE: رسالة خطأ بعد عملية الاضافة - princelovelorn - 16-02-19

جرب الكود التالي
وهو تحويل قيم الحقول النصية الى 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



RE: رسالة خطأ بعد عملية الاضافة - اللورد محمود - 16-02-19

جرب هذه اخي مع تغير مسمى الادوات 

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 



RE: رسالة خطأ بعد عملية الاضافة - georgos - 16-02-19

اخي شكرا لك لكن لم افهم شيئ من الكود !! اسماء الادوات موجودين هنا بالصورة هل يمكن تعديل الكود من بعد اذنك !



RE: رسالة خطأ بعد عملية الاضافة - princelovelorn - 16-02-19

جرب الكود التالي 
وعلى فكرة هو يعمل جيدا وتم تجربته

كود :
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



RE: رسالة خطأ بعد عملية الاضافة - georgos - 16-02-19

اخي نفس المشكلة و هي لم تكن موجودة
ضهرت من بعد كود حساب المجموع الاجمالي
كود :
 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



RE: رسالة خطأ بعد عملية الاضافة - princelovelorn - 16-02-19

لو سمحت أرفع المشروع الذي تعمل عليه للتعديل عليه مباشرة


RE: رسالة خطأ بعد عملية الاضافة - georgos - 16-02-19

(16-02-19, 01:21 AM)princelovelorn كتب : لو سمحت أرفع المشروع الذي تعمل عليه للتعديل عليه مباشرة
هذا الملف مع صور لشرحه لانه باللغة الانكليزية و السويدية
[attachment=20873]
[attachment=20874]
[attachment=20875]