从字符串“"转换输入“整数"无效. [英] Conversion from string "" to type 'Integer' is not valid.

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

问题描述

Protected Sub GridView1_RowUpdating(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim ID As String = GridView1.Rows(e.RowIndex).Cells(0).Text

        Dim Company As String = (CType(GridView1.Rows(e.RowIndex).Cells(1).Controls(0), TextBox)).Text
        Dim Name As String = (CType(GridView1.Rows(e.RowIndex).Cells(2).Controls(0), TextBox)).Text
        Dim Title As String = (CType(GridView1.Rows(e.RowIndex).Cells(3).Controls(0), TextBox)).Text
        Dim Address As String = (CType(GridView1.Rows(e.RowIndex).Cells(4).Controls(0), TextBox)).Text
        Dim Country As String = (CType(GridView1.Rows(e.RowIndex).Cells(5).Controls(0), TextBox)).Text

        Dim UpdateOrAddNewRecord(ID, Company, Name, Title, Address, Country, True)
        GridView1.EditIndex = -1
        BindGridView()
    End Sub

推荐答案

您是否真的对ID列使用了字符串(即char,nchar,varchar或nvarchar)?我希望它是一个将"identity"设置为true的整数,即服务器上自动生成的值.
通常,SQLServer不允许您插入标识值(除非您明确更改了该设置,否则除外).
空字符串永远不是有效的整数值.
我知道MySQL默认允许插入标识值-当您使用"0"时,它将替换为自动生成的值(但我不知道它在该位置如何处理空字符串).
但是,由于您使用的是SQLServer,因此请更改代码:不要在INSERT语句中使用ID值!
Do you really use a string (i.e. char, nchar, varchar, or nvarchar) for the ID column??? I would rather expect it to be an integer with "identity" set to true, i.e. an automatically generated value on the server.
And normally, SQLServer won''t allow you to insert the identity value (except when you explicitly changed that setting).
And an empty string is never a valid integer value.
I know that MySQL allows the insertion of identity values by default - and when you use "0", it replaces that with an automatically generated value (but I do not know how it treats an empty string in that place).
But since you are using SQLServer, change your code: do not use the ID value in the INSERT statement!


检查方法的签名是否如下所述

Check if the signature of the method is as follows

Dim UpdateOrAddNewRecord(Dim ID As String,Dim  Company As String , Dim Name as String,Dim Title as String,Dim Address As String,Dim Country as String,Dim flag as booean)



您需要根据功能更改此方法的签名或上面的代码中声明的数据类型



Either you need to change the signature of this method or the datatypes declared in the above code as per your functionality


这篇关于从字符串“"转换输入“整数"无效.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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