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. 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:
<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.
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. I'd also use CTYPE and 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.