Input string was not in a correct format.
Hi,
I am trying to make a C/ODBC connection with a Navision Database through ASP.NET. This works good, but when i try to get other values other than CODE or TEXT, i get the error shown in the subject.
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dsn As String
Dim sql As String
Dim cn As OdbcConnection
Dim cmd As OdbcCommand
Dim dr As OdbcDataReader
dsn = "DRIVER={C/ODBC 32 bit};"
dsn = dsn & "DSN=DSNNAME;"
dsn = dsn & "UID=user;"
dsn = dsn & "PWD=pwd;"
dsn = dsn & "sName=SRVRNAME;"
dsn = dsn & "NType=tcp;"
dsn = dsn & "CN=My Company;"
dsn = dsn & "CSF=Yes;"
dsn = dsn & "SERVER=N"
cn = New OdbcConnection(dsn)
cn.Open()
sql = "SELECT No_, Name, Address, City, ""Phone No_"", Amount FROM "
Select Case Request.QueryString("Table")
Case 90000
sql = sql & "Cust50"
Case 90001
sql = sql & "Cust500"
Case 90002
sql = sql & "Cust500"
Case 90003
sql = sql & "CustFull"
End Select
cmd = New OdbcCommand(sql, cn)
dr = cmd.ExecuteReader(CommandBehavior.SingleResult)
dtgCustomers.DataSource = dr
dtgCustomers.DataBind()
lblElapsed.Text = "Time needed to load: " & Environment.TickCount - Request.QueryString("ms") & " Milliseconds"
cn.Close()
End sub
Does anyone know how i can solve this or at least make it be shown or parsed to string(the values do not have to be edited).
It is the Amount field that has the type Decimal.
Hope anyone can help me.
Greets,
Freightliner
[EDIT:] Forgot to say i get the error when i connect it to the datagrid:
Quote:
Server Error in '/WebApplication1' Application.
--------------------------------------------------------------------------------
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 63:
Line 64: dtgCustomers.DataSource = dr
Line 65: dtgCustomers.DataBind()
Line 66: lblElapsed.Text = "Time needed to load: " & Environment.TickCount - Request.QueryString("ms") & " Milliseconds"
Line 67:
Source File: c:\inetpub\wwwroot\WebApplication1\CODBC.aspx.vb Line: 65
Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Number.ParseDecimal(String s, NumberStyles style, NumberFormatInfo info) +0
System.Decimal.Parse(String s, IFormatProvider provider) +28
System.Data.Odbc.OdbcDataReader.internalGetDecimal(Int32 i)
System.Data.Odbc.OdbcDataReader.GetValue(Int32 i, TypeMap typemap)
System.Data.Odbc.OdbcDataReader.GetValue(Int32 i)
System.Data.Odbc.OdbcDataReader.GetValues(Object[] values)
System.Data.Common.DbEnumerator.MoveNext()
System.Web.UI.WebControls.DataGrid.CreateAutoGeneratedColumns(PagedDataSource dataSource)
System.Web.UI.WebControls.DataGrid.CreateColumnSet(PagedDataSource dataSource, Boolean useDataSource)
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
WebApplication1.CODBC.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\WebApplication1\CODBC.aspx.vb:65
System.Web.UI.Control.OnLoad(EventArgs e)
System.Web.UI.Control.LoadRecursive()
System.Web.UI.Page.ProcessRequestMain()
--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573