I have this aspx program but I m getting error following is my program code can someone plese help me!!!! ' Insert page code here ' Function GetFileNameSet(ByVal DIXIE As Double) As System.Data.DataSet Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;
Ole DB Services=-4; Data Source=C:\Inetpub\wwwr"& _ "oot\aaa\mydir\image.xls" + ";" +"Extended Properties=Excel 8.0;" 'Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\Inetpub\wwwr"& _ '"oot\aaa\mydir\image.mdb"
Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString) Dim queryString As String = "SELECT * FROM [Sheet1$] WHERE ([Sheet1$].[Seq] = @Seq)" Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
dbCommand.CommandText = queryString dbCommand.Connection = dbConnection Dim dbParam_seq As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter dbParam_seq.ParameterName = "@DIXIE" dbParam_seq.Value = DIXIE dbParam_seq.DbType = System.Data.DbType.Double
dbCommand.Parameters.Add(dbParam_seq) Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter dataAdapter.SelectCommand = dbCommand Dim dataSet As System.Data.DataSet = New System.Data.DataSet dataAdapter.Fill(dataSet) Return
dataSet End Function 'From asp.net Help Function IsNull(ByVal dbValue As Object, ByVal ReplaceValue As Object) As Object If dbValue Is DBNull.Value Then Return ReplaceValue Else Return dbValue End If End Function Sub btnSearch_Click(sender As Object, e As
EventArgs) Dim I As string I = txtPart.text Dim DS As System.Data.DataSet = New System.Data.DataSet DS = GetFileNameSet(I) '0 'txtSeq.text = CType(DS.Tables(0).Rows(0).Item(0),String) '1 txtPart.text = DS.Tables(0).Rows(0).Item(1) '2 txtImage1.text = DS.Tables(0).Rows(0).Item(2)
'3 txtImage2.text = DS.Tables(0).Rows(0).Item(3) '4 txtImage3.text = DS.Tables(0).Rows(0).Item(4) '5 txtImage4.text = DS.Tables(0).Rows(0).Item(5) '6 txtImage5.text = DS.Tables(0).Rows(0).Item(6) '7 txtImage6.text = CType(DS.Tables(0).Rows(0).Item(7),String)
'12 txtSpd.text = CType(DS.Tables(0).Rows(0).Item(12),String) 'txtspd.text = Cstr(Me.IsNull(DS.Tables(0).Rows(0).Item(12), "")) '15 txtOePt.text = CType(DS.Tables(0).Rows(0).Item(15),String) '13 txtRegFan.text = CType(DS.Tables(0).Rows(0).Item(13),String)
'16 txtOePt2.text = CType (DS.Tables(0).Rows(0).Item(16),String) '17 txtvoltage.text = ctype(DS.Tables(0).Rows(0).Item(17),string) 'txtvoltage.text = Cstr(Me.IsNull(DS.Tables(0`).Rows(0).Item(17), "")) End Sub Following is the error I m getting.... Server
Error in '/' Application. -------------------------------------------------------------------------------- Cast from type 'DBNull' to type 'String' is not valid. 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.InvalidCastException: Cast from type 'DBNull' to type 'String' is not valid. Source Error: Line 114: txtOePt2.text = CType (DS.Tables(0).Rows(0).Item(16),String)
Line 115: '17 Line 116: txtvoltage.text = ctype(DS.Tables(0).Rows(0).Item(17),string) Line 117: 'txtvoltage.text = Cstr(Me.IsNull(DS.Tables(0`).Rows(0).Item(17), "")) Line 118: Source File: c:\inetpub\wwwroot\aaa\ulookup05.aspx Line: 116 Stack Trace: [InvalidCastException:
Cast from type 'DBNull' to type 'String' is not valid.] Microsoft.VisualBasic.CompilerServices.StringType.FromObject(Object Value) +616 ASP.ULookup05_aspx.btnSearch_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\aaa\ulookup05.aspx:116 System.Web.UI.WebControls.Button.OnClick(EventArgs
e) +108 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection
postData) +33 System.Web.UI.Page.ProcessRequestMain() +1292
You have to check for null, as such: if (not DS.Tables(0).Rows(0).IsNull(17)) then txtvoltage.text = .. end if Brian
Brian
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
in my program i have a textbox which i want to enter a partnumber lets say something like A-1234 and my program will check that with the database and give me the output or the result. but whats happening is that when i enter a character A- it gives me error
if i have a partnumber with only lets say 1234 then it workds fine but it does not work when my part number has A- with the digit...Can someone help me why it does not work if u want me to post a code let me know... Thanks follwoing is the error message i
get when i try to enter the partnumber in textbox as A-1234 Server Error in '/' 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
80: 'For I = 24831 to 24831 Line 81: Dim DS As System.Data.DataSet = New System.Data.DataSet Line 82: DS = GetFileNameSet(I) Line 83: Source File: c:\inetpub\wwwroot\aaa\ulookup05.aspx Line: 82 Stack Trace: [FormatException: Input string was not in a correct
format.] Microsoft.VisualBasic.CompilerServices.DoubleType.Parse(String Value, NumberFormatInfo NumberFormat) +195 Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String Value, NumberFormatInfo NumberFormat) +82 [InvalidCastException: Cast from
string "a-8790" to type 'Double' is not valid.] Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String Value, NumberFormatInfo NumberFormat) +168 Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String Value) +7 ASP.ULookup05_aspx.btnSearch_Click(Object
sender, EventArgs e) in c:\inetpub\wwwroot\aaa\ulookup05.aspx:82 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain() +1292
It doesn't work because GetFileNameSet only accepts a double parameter, as is set by the error: [InvalidCastException: Cast from string "a-8790" to type 'Double' is not valid.] All you have to do it change your function to accept a string instead, or remove
the a- from your number, as such: 'Starts at 8 and continues to the end. GetFileNameSet(I.Substring(2)) Brian
Brian
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
thaks brain I can not remvoe a- from my partnumber my user will have to enter that in the textbox to look for the info. so as u said change my function to accept the string but can u show me how it can be done please.... thanks.
Change: Function GetFileNameSet(ByVal DIXIE As Double) As System.Data.DataSet To: Function GetFileNameSet(ByVal DIXIE As String) As System.Data.DataSet Remember a double only accepts numeric fields, not the "a-". Setting to string may give you a few errors,
which you can easily fix (because of the conversion). Brian
Brian
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
Altafingar
Participant
1275 Points
271 Posts
aspx file error please help
Jan 04, 2005 02:39 PM|LINK
bmains
All-Star
29116 Points
5886 Posts
MVP
Re: aspx file error please help
Jan 04, 2005 07:39 PM|LINK
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
Altafingar
Participant
1275 Points
271 Posts
Re: aspx file error please help
Jan 05, 2005 12:45 PM|LINK
Altafingar
Participant
1275 Points
271 Posts
Re: aspx file error please help
Jan 05, 2005 03:23 PM|LINK
bmains
All-Star
29116 Points
5886 Posts
MVP
Re: aspx file error please help
Jan 05, 2005 04:37 PM|LINK
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
Altafingar
Participant
1275 Points
271 Posts
Re: aspx file error please help
Jan 05, 2005 05:14 PM|LINK
bmains
All-Star
29116 Points
5886 Posts
MVP
Re: aspx file error please help
Jan 05, 2005 05:41 PM|LINK
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
Altafingar
Participant
1275 Points
271 Posts
Re: aspx file error please help
Jan 05, 2005 05:47 PM|LINK
bmains
All-Star
29116 Points
5886 Posts
MVP
Re: aspx file error please help
Jan 05, 2005 07:50 PM|LINK
"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
Altafingar
Participant
1275 Points
271 Posts
Re: aspx file error please help
Jan 10, 2005 01:53 PM|LINK