从字符串& quot;& quot;转换键入' Decimal'无效.......... [英] Conversion from string "" to type 'Decimal' is not valid..........

查看:63
本文介绍了从字符串& quot;& quot;转换键入' Decimal'无效..........的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<跨度风格= "颜色:#666666;字体家庭: '的Segoe UI',黑体,迦楼,Arial字体,无衬线;字体大小:14px的">我有这样的代码,它提供与错误"从字符串转换为十进制类型无效

Private Sub btnadd_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理btnadd.Click

  &NBSP; &NBSP; &NBSP;如果txtbookID.Text.Length = 0或者txtauthor.Text.Length = 0或者是
  &NBSP; &NBSP; &NBSP; txttitle.Text.Length = 0或txtpurchaseprice.Text.Length = 0或者
  &NBSP; &NBSP; &NBSP; txtsaleprice.Text.Length = 0或txtinventory.Text.Length = 0然后

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; MessageBox.Show("请输入所有数据。")

  &NBSP; &NBSP; &NBSP;否则

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; MessageBox.Show("系统会将新记录存储到数据库中。")
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; btnclear.PerformClick()

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; lblnumberofrecords.Text = lblnumberofrecords.Text()



$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;暗淡abookID作为新clsBook(txtbookID.Text,txtauthor.Text,txttitle.Text,CDEC(txtpurchaseprice.Text),

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP ;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; CDEC(txtsaleprice.Text),CINT(txtinventory.Text))



  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; lblnumberofrecords.Text = books.Count

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; MessageBox.Show("添加到数据库的记录"。)

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; btnclear.PerformClick()

Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
        If txtbookID.Text.Length = 0 Or txtauthor.Text.Length = 0 Or
        txttitle.Text.Length = 0 Or txtpurchaseprice.Text.Length = 0 Or
        txtsaleprice.Text.Length = 0 Or txtinventory.Text.Length = 0 Then
            MessageBox.Show("Please enter all data.")
        Else
            MessageBox.Show("The system will store the new record into the database.")
            btnclear.PerformClick()
            lblnumberofrecords.Text = lblnumberofrecords.Text()


            Dim abookID As New clsBook(txtbookID.Text, txtauthor.Text, txttitle.Text, CDec(txtpurchaseprice.Text),
                                       CDec(txtsaleprice.Text), CInt(txtinventory.Text))

            lblnumberofrecords.Text = books.Count
            MessageBox.Show("records added to the database.")
            btnclear.PerformClick()

推荐答案

b $ b
 Dim abookID As New clsBook 
  (txtbookID.Text, txtauthor.Text, txttitle.Text, 
   CDec(txtpurchaseprice.Text), CDec(txtsaleprice.Text), 
   CInt(txtinventory.Text))


。您正在使用CDEC对一些数字值转换为十进制。

我想[txtpurchaseprice],[txtsaleprice]或[txtinventory ]具有无法转换为十进制的值。



在使用[abookID]之前,您需要检查这些控件的值是否可以转换为十进制。 />


问候,

You are using CDEC for converting some numeric value to Decimal.
I suppose [txtpurchaseprice], [txtsaleprice], or [txtinventory] has a value that cannot be converted to Decimal.

You need to check if value of these controls can be converted into Decimal, before using [abookID].

Regards,


这篇关于从字符串&amp; quot;&amp; quot;转换键入&amp;#39; Decimal&amp;#39;无效..........的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆