Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by mike55

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
Posted

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.

[sIGPIC]e[/sIGPIC]
Posted
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...