Hello, How can input number to database where my field in database data type money..

This is my code:

Private Sub SaveData()

        Try
            If adcLEDGER.State = ADODB.ObjectStateEnum.adStateOpen Then adcLEDGER.Close()
            adcLEDGER.ConnectionString = strCONNECT
            adcLEDGER.Open()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        Try
            Dim vANSWER
            vANSWER = vbYes

            modPY.LookUpST(adcLEDGER, "SELECT * FROM MS_UMR WHERE TAHUN = '" & Trim(txtTahun.Text) & "'", strTahun) ' And (CStr(Trim(strKEY)) <> CStr(Trim(txtTahun.Text))))
            If strTahun <> Nothing Then
                vANSWER = MsgBox("Data sudah ada, yakin akan di replace......", vbYesNo, "Update")
                If vANSWER = vbYes Then
                    cSQL = "UPDATE MS_UMR SET Sehari = CONVERT(money, '" & Val(Format(txtSehari.Text, formatSAVE)) & "'), Sebulan = CONVERT(money, '" & Val(Format(txtSebulan.Text, formatSAVE)) & "'), Nomor = '" & Trim(txtNoKeputusan.Text) & "' WHERE TAHUN = '" & Trim(txtTahun.Text) & "'"

                    adcLEDGER.Execute(cSQL)
                    showdata()
                    bersihForm()
                Else
                    showdata()
                    bersihForm()
                End If

            Else
                cSQL = "INSERT INTO MS_UMR(TAHUN,SEHARI,SEBULAN,NOMOR) VALUES('" & Trim(txtTahun.Text) & "', CONVERT(money,'" & Val(Format(txtSehari.Text, formatSAVE)) & "'), CONVERT(money,'" & Val(Format(txtSebulan.Text, formatSAVE)) & "'),'" & Trim(txtNoKeputusan.Text) & "')"
                adcLEDGER.Execute(cSQL)
                showdata()
                bersihForm()
            End If

        Catch ex As Exception
            MsgBox(ex.Message)


        End Try

    End Sub


Private Sub txtSehari_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtSehari.LostFocus
        txtSehari.Text = Format(Convert.ToDouble(txtSehari.Text), "#,###0.00")
    End Sub

When i tray to input success, But when i cek in my database with field data type money not i want. Example:

Result:
- I want: 10,000.00(My application) - 10000(My database with data type money), But that appears 10(in my database with data type money). Why??
What's wrong with my code???

Thank's for your answer my question...

Stop building your queries dynamically and treating the money as string would be a good start. Use parameterized SQL:

Here is a select example but just change your insert queries and use @Parameters

Imports System
Imports System.Collections
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Imports System.Windows.Forms
Imports System.Data.SqlClient


Public Class MainClass
    Shared Dim WithEvents con As SqlConnection

    Shared Sub Main()
        con = New SqlConnection("Server=(local)\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=SSPI") 

        Dim cmd As New SqlCommand("SELECT FirstName, LastName FROM Employee WHERE FirstName = @fn", con)
        cmd.Parameters.Add(New SqlParameter("@fn", SqlDbType.VarChar, 10)).Value = "Joe"

        Try
            con.Open()
            Dim reader As SqlDataReader = cmd.ExecuteReader()
            While reader.Read()
                Console.WriteLine("{0} - {1}", reader.GetString(0), reader.GetString(1))
            End While
            reader.Close()
        Finally
            con.Close()
        End Try
    End Sub
End Class

Borrowed from:
http://www.java2s.com/Code/VB/Database-ADO.net/PassParameterintoSQLcommand.htm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.