4 Replies - 1331 Views - Last Post: 21 August 2009 - 12:14 AM Rate Topic: -----

#1 xoops   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 81
  • Joined: 06-August 09

I can't input number to database where my field type data money

Posted 19 August 2009 - 11:44 PM

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...

Is This A Good Question/Topic? 0
  • +

Replies To: I can't input number to database where my field type data money

#2 motcom   User is offline

  • D.I.C Lover
  • member icon

Reputation: 293
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: I can't input number to database where my field type data money

Posted 20 August 2009 - 06:43 AM

Hi Xoops,

Sometimes the "," int the text does not convert well.

The CDBL() function should do the trick.

Try like this
cSQL = "UPDATE MS_UMR SET Sehari = " & cdbl(txtSehari.Text) & ", Sebulan = " & cdbl(txtSebulan.Text) & ", Nomor = '" & Trim(txtNoKeputusan.Text) & "' WHERE TAHUN = '" & Trim(txtTahun.Text) 

Was This Post Helpful? 0
  • +
  • -

#3 xoops   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 81
  • Joined: 06-August 09

Re: I can't input number to database where my field type data money

Posted 20 August 2009 - 06:47 PM

Hi Motcom,

It's still not working..

This post has been edited by xoops: 20 August 2009 - 06:48 PM

Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: I can't input number to database where my field type data money

Posted 20 August 2009 - 07:10 PM

Try using Decimal for Currancy
Was This Post Helpful? 0
  • +
  • -

#5 motcom   User is offline

  • D.I.C Lover
  • member icon

Reputation: 293
  • View blog
  • Posts: 1,371
  • Joined: 16-June 08

Re: I can't input number to database where my field type data money

Posted 21 August 2009 - 12:14 AM

Should this line of code

txtSehari.Text = Format(Convert.ToDouble(txtSehari.Text), "#,###0.00")


not be ?

txtSehari.Text = Format(Convert.ToDouble(txtSehari.Text), "#,##0.00")


if it still does not work try using typed datasets with table adapters or parameters for your querry.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1