我是VB.Net和Access的新手。我试图在TextBox中捕获值,然后将其转换为负值并将其存储在数据库中。 无论我做什么,它仍然将值存储在正整数中。
先谢谢
这是我的代码:
Public Class Form3
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim sqlconn As New OleDb.OleDbConnection
Dim sqlquery As New OleDb.OleDbCommand
Dim connString As String
connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\neetals\Documents\Visual Studio 2010\Projects\xx\xx\DailyTotal.mdb"
Dim xAmt As Integer
xAmt = Convert.ToDecimal(txtAmt.Text)
xAmt = (xAmt * -1)
If String.IsNullOrEmpty(txtAmt.Text) Then
MsgBox("Amount Value Cannot be Empty")
ElseIf String.IsNullOrEmpty(txtNotes.Text) Then
MsgBox("Notes Cannot be Empty")
Else
sqlquery.Parameters.AddWithValue("@xdate", DateTimePicker1)
sqlquery.Parameters.AddWithValue("@xAmt", txtAmt.Text)
sqlquery.Parameters.AddWithValue("@note", txtNotes.Text)
Try
sqlconn.ConnectionString = connString
sqlquery.Connection = sqlconn
sqlconn.Open()
sqlquery.CommandText = "INSERT INTO Cash(cdate, cAmt, cNotes) VALUES(@xdate,@xAmt, @note)"
'Math.Abs(-xAmt)
sqlquery.ExecuteNonQuery()
sqlconn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End If
End Sub
结束班
答案 0 :(得分:0)
你计算你的价值......
xAmt = Convert.ToDecimal(txtAmt.Text)
xAmt = (xAmt * -1)
但是你不能使用xAmt
变量,但是再次使用文本框(仍然具有原始值):
sqlquery.Parameters.AddWithValue("@xAmt", txtAmt.Text)