mike55 Posted May 16, 2005 Posted May 16, 2005 (edited) Hi, I am encountering the following error: System.InvalidCastException: Cast from string "SELECT Email_Add FROM Login wher" to type 'Double' is not valid. ---> System.FormatException: Input string was not in a correct format. at Microsoft.VisualBasic.CompilerServices.DoubleType.Parse(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String Value, NumberFormatInfo NumberFormat) --- End of inner exception stack trace --- at Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String Value, NumberFormatInfo NumberFormat) at Microsoft.VisualBasic.CompilerServices.DoubleType.FromString(String Value) at MsgWebService.moduleMessage.getSendersEmail(Int16 senderID) in c:\inetpub\wwwroot\MsgWebService\myModules\moduleMessage.vb:line 254 at MsgWebService.moduleMessage.sendMessage(DataRow messageDetails) in c:\inetpub\wwwroot\MsgWebService\myModules\moduleMessage.vb:line 133 at MsgWebService.wsSendMessages.sendMessage() in c:\inetpub\wwwroot\MsgWebService\wsSendMessages.asmx.vb:line 94 at MsgWebService.wsSendMessages.startProcessing() in c:\inetpub\wwwroot\MsgWebService\wsSendMessages.asmx.vb:line 57 The code that I am using is: localConnection() 'Open a connection to the database. 'Set-up the command sqlCommand.Connection = conSQL sqlCommand.CommandType = CommandType.Text sqlCommand.CommandText = "SELECT Email_Add FROM Login where Group_HeadID = " + senderID Try getSendersEmail = sqlCommand.ExecuteScalar 'Execute the statement Return getSendersEmail.ToString Catch Finally conSQL.Close() 'Close the database connection. End Try From what I can see, my SQL statement is correct, and the connection is being opened correctly. The problem seems to occure when I try and assign the sql statement to the sqlconnection. The sqlconnection is defined as a new sqlconnection, and as a global variable. Any suggestions?? Mike55 Edited May 16, 2005 by mike55 Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Leaders snarfblam Posted May 16, 2005 Leaders Posted May 16, 2005 Are you using option strict? (If you arent, you probably should be.) Try changing sqlCommand.CommandText = "SELECT Email_Add FROM Login where Group_HeadID = " + senderID To sqlCommand.CommandText = "SELECT Email_Add FROM Login where Group_HeadID = " & senderID.ToString When joining strings, & is usually better than + because + might be interpreted as addition rather than concatenation. Quote [sIGPIC]e[/sIGPIC]
kejpa Posted May 17, 2005 Posted May 17, 2005 sqlCommand.CommandText = "SELECT Email_Add FROM Login where Group_HeadID = " + senderID You're trying to add a string to a double. That's what the first line of the error message tells you (or at least me ;)) Cast your senderID to a string and you'll be fine. sqlCommand.CommandText = "SELECT Email_Add FROM Login where Group_HeadID = " + senderID[b].tostring[/b] HTH /Kejpa Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.