将新记录添加到DataTable中的转换无效 [英] Invalid conversion in adding new records to DataTable

查看:66
本文介绍了将新记录添加到DataTable中的转换无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,um正在尝试使用此代码在表中添加新记录,但其从字符串插入id_mst_department va"到"double"类型的转换无效."什么意思!

Now um trying to add new records in the a table using this code but its has "conversion from string "insert into id_mst_department va" to type ''double'' is not valid." what does it mean!

Public Sub lp_Save()

        Dim li_DEPARTMENT_ID As Integer
        Dim ls_DEPARTMENT_NAME As String
        Dim ls_DEPARTMENT_LOCATION_NAME As String
        Dim lV_DEPARTMENT_ROOM_NUMBER As String
        Dim ls_DEPARTMENT_STATUS As String
        Dim ls_costr As String
        ls_costr = "Data Source=DEFAULT-PC;Initial Catalog=IDMS_DEV;User ID=sa;Password=develop"
        li_DEPARTMENT_ID = Val(txt_id.Text)
        ls_DEPARTMENT_NAME = txt_name.Text
        ls_DEPARTMENT_LOCATION_NAME = txt_location.Text
        lv_DEPARTMENT_ROOM_NUMBER = txt_number.Text
        ls_DEPARTMENT_STATUS = txt_status.Text
        Dim lo_con As SqlConnection
        lo_con = New SqlConnection(ls_costr)
        lo_con.Open()
        Dim ls_cmd As String
        ls_cmd = "Insert into ID_MST_DEPARTMENT values('"
        ls_cmd = ls_cmd + li_DEPARTMENT_ID + ls_DEPARTMENT_NAME + "','" + ls_DEPARTMENT_LOCATION_NAME + "','" + lv_DEPARTMENT_ROOM_NUMBER + ",'" + ls_DEPARTMENT_STATUS + "')"
        Dim LO_SQLCOMMAND As SqlCommand
        LO_SQLCOMMAND = New SqlCommand(ls_cmd, lo_con)
        LO_SQLCOMMAND.ExecuteNonQuery()
        Response.Redirect("frm_LISTING_PAGE.aspx")
    End Sub

推荐答案

您正在使用"+"合并字符串.
但是"id_mst_department"是数字.因此,它显示错误,因为字符串和数字不能执行sum

将"id_mst_department"转换为字符串,然后将其与您的字符串合并.

只需使用,
you are using ''+'' to merge string.
but ''id_mst_department'' is numeric. so, it''s showing error because string and digits can not perform sum

convert ''id_mst_department'' to string then you will able to merge this with in your string.

simply use,
id_mst_department.Tostring()



祝您编码愉快!
:)



Happy Coding!
:)


这篇关于将新记录添加到DataTable中的转换无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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