[英]Input string in correct format. VB.net - New to this so help required
i am having some issues with a page and the code behind i am working on.我在处理页面和背后的代码时遇到了一些问题。 please see the code:请看代码:
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim dtTable As DataTable = Nothing
Dim intConnectionId As Integer = 0
If Page.IsPostBack Then
' Get user data from session
With HttpContext.Current
intConnectionId = CInt(result.Value)
End With
End If
' Remove connection
modConnections.Delete(intConnectionId)
' Clear desks attahced to connection
modDeskText.ClearUserDesk(intConnectionId)
Using sqlCommand As New SqlCommand
With sqlCommand
.CommandText = "usp_connectsdetailedlist"
.CommandType = CommandType.StoredProcedure
End With
Execute(sqlCommand, dtTable)
End Using
With Rep1
.DataSource = dtTable.DefaultView
.DataBind()
End With
If Not IsNothing(dtTable) Then
dtTable.Dispose()
End If
End Sub
[FormatException: Input string was not in a correct format.]
Microsoft.VisualBasic.CompilerServices.Conversions.ParseDouble(String Value, NumberFormatInfo NumberFormat) +213
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +90
[InvalidCastException: Conversion from string "" to type 'Integer' is not valid.]
Microsoft.VisualBasic.CompilerServices.Conversions.ToInteger(String Value) +238
frmConnects2.Page_Load(Object sender, EventArgs e) in D:\Source Code\PTS\PTS Online .NET - Copy\PTS Online .NET\PTS Online .NET stu\frmConnects2.aspx.vb:17
System.Web.UI.Control.OnLoad(EventArgs e) +95
System.Web.UI.Control.LoadRecursive() +59
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678
On the line:在线上:
intConnectionId = CInt(result.Value)
I am getting the above error.我收到上述错误。 No matter what i do i cannot get the data to convert to the format i need to work.无论我做什么,我都无法将数据转换为我需要工作的格式。 I now understand this has nothing to do with the right hand side code.我现在明白这与右侧代码无关。
My goal is to get the data from a table, place in into the text box ( <input type="text" id="result" runat="server" />
) id="result" and then use the "id" of the record selected in SQL to remove the connection.我的目标是从表中获取数据,放入文本框 ( <input type="text" id="result" runat="server" />
) id="result" 然后使用“id”在 SQL 中选择的记录的删除连接。 see table below:见下表:
<ItemTemplate>
<tr class="<%# ReturnValuesAsColor(Eval("online"), Eval("mobile"), Eval("server_proc"))%>">
<td><%# Eval("id").ToString%></td>
<td><%# Eval("user_id").ToString%></td>
<td><%# Eval("user_name").ToString%></td>
<td><%# Eval("workstation_name").ToString%></td>
<td><%# Eval("ip_address").ToString%></td>
<td><%# Eval("connect_date").ToString%></td>
<td><%# Eval("refresh_date").ToString%></td>
<td><%# Eval("app_ver").ToString%></td>
<td><%# Eval("app_date").ToString%></td>
<td><%# CBool(Eval("get_messages_flag")).ToString%></td>
<td><%# FixNumbers(Eval("message_type_flags"))%></td>
<td><%# Eval("online").ToString%></td>
<td><%# Eval("mobile").ToString%></td>
<td><%# Eval("group_name").ToString%></td>
<td><%# Eval("server_proc").ToString%></td>
<td><input type="submit" class="ui-button ui-widget ui-state-default ui-corner-all" value="delete connection" onclick="clearText(result); CopyId(<%# Eval("id").ToString%>);" /></td>
</tr>
</ItemTemplate>
JS used:使用的JS:
<script>
function CopyId(num) {
var txt = document.getElementById("<%= result.ClientID%>").value;
txt = num;
document.getElementById("<%= result.ClientID%>").value = txt;
}
</script>
Sorry if i missed anything or there is a lack of info.抱歉,如果我错过了什么或缺少信息。 Any help much appreciated.非常感谢任何帮助。
You haven't shown us the definition for result
or result.Value
so this is an educated guess.您尚未向我们展示result
或result.Value
的定义,因此这是一个有根据的猜测。
Try testing for a null value in the database:尝试测试数据库中的空值:
If IsDbNull(result.Value) Then
intConnectionId = 0
Else
intConnectionId = CInt(result.Value)
End If
in VB you need to check your variable to ensure it is not empty, null, & nothing and does not contain any non numeric characters.在 VB 中,您需要检查您的变量以确保它不是空的、空的和没有的,并且不包含任何非数字字符。 I'd also use CTYPE and Trim.我也会使用 CTYPE 和 Trim。 The Conversion will only work if the string contains a numeric value.只有当字符串包含数字值时,转换才会起作用。 If you are having a problem populating the string then you need to check the code where it's populated.如果您在填充字符串时遇到问题,那么您需要检查填充它的代码。 I'm afraid I don't know JS.恐怕我不知道JS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.