cmaras Posted November 3, 2003 Posted November 3, 2003 Visual Basic .NET Ok, I have been reading about these conversion problems on this forum and if I get it right, why it would like to convert a String into a Double wóuld be if you are doing some kind or mathematical operation with that value like: Dim strvalue = "VelevetBoo" strValue = strValue / 2 this would force .NET to try converting the String to a Double or Integer to try to solve the problem, this is where it will throw the exception because it can't convert characters to numbers. Just trying to find out where I am wrong in my thinking, just giving you an idea where I'm coming from. Ok my problem comes from a Method where I feed it data through parameters it looks like this. Public Sub UpdateDataAdapter(ByVal Exp_Date As String, ByVal Rec_Type As String, _ ByVal IPStart_Rng As String, ByVal IPEnd_Rng As String, ByVal Room As String, _ ByVal Detail As String, ByVal Nickname As String) I use the following code to fill the parameters: UpdateDataAdapter(txtExp_Date.Text, txtRec_Type.Text, + _ strStartIP, strEndIP, cmbRoom.Text, txtDetail.Text, + _ txtNickname.Text) All these parameters are of the String data type, either TextBox's or Variables defined As String. My problem is that the Textbox txtNickname results in the error: Cast from string "VelvetBoo" to type 'Double' is not valid I can't see the problem, I'm not doing any kind of mathematical operation on this value so why does it want to convert it to Double? All I want is it to read it into the UpdateDataAdapter method and to use the data to populate an update statement which looks like this. objDBconn.Open() objDataAdapter.UpdateCommand = New OleDb.OleDbCommand() objDataAdapter.UpdateCommand.CommandText = "UPDATE " + strTable + " SET " + _ "[Exp_Date] = " + Exp_Date + ", [Rec_Type] = " + Rec_Type + ", [iPStart_Rng] = " + IPStart_Rng + ", " + _ "[iPEnd_Rng] = " + IPEnd_Rng + ", [Room] = " + Room + ", [Detail] = " + Detail + ", " + _ "[Nickname] = " + Nickname + _ "Where [iD] = " + strCurrentID objDataAdapter.UpdateCommand.Connection = objDBconn objDataAdapter.UpdateCommand.ExecuteNonQuery() objDBconn.Close() End Sub I realize that this might not be the optimal way to use SQL in code but I'm a beginner so if you have any pointers please do tell. Personally I find it a bit cumbersom to write SQL querys in code, so if there is a better way I'm all ears. But either way I would like to know why .NET is doing this conversion. Thank you for listening and I appriciate your help. Claudio Quote
Administrators PlausiblyDamp Posted November 3, 2003 Administrators Posted November 3, 2003 If you are concatenating strings use & instead of + as + is a mathematical operator that can double as a string operator - this could be causing the problem. A better way would be to use server side stored procedures - search these forums and MSDN for a lot more information on Stored Procedures. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
cmaras Posted November 3, 2003 Author Posted November 3, 2003 Thanks for your post, I haven't changed the + to & yet but sounds like a good idea. Regarding the Server-side Stored Procedures it's an Access Database so I don't know if you have the option of stored procedures. But thanks for your suggestion. Claudio Quote
cmaras Posted November 3, 2003 Author Posted November 3, 2003 Well it's been proven I'm a moron, well as anybody who probably looked at this code saw. Again thanx for the pointer "PlausiblyDamp" you pointed me in the right direction. The problem was that I was binding controls and variables together which doesn't require + or &. So I removed the + from the UpdateDataAdapter() and everything was back to normal. Again tahnx again for you extreamly fast reply "PlausiblyDamp". Claudio Quote
Administrators PlausiblyDamp Posted November 3, 2003 Administrators Posted November 3, 2003 Not sure if Access does suppor them or not either. You may want to investigate MSDE from Microsoft which gives you a SQL server compliant engine - works well with access as a front end. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
cmaras Posted November 3, 2003 Author Posted November 3, 2003 Correction I'm NOT binding the control or variables together, what I wanted to say was I wasn't binding control or variables with text. I hope taht makes sense. Claudio Quote
*Experts* Nerseus Posted November 3, 2003 *Experts* Posted November 3, 2003 Yes, from what I've read on other threads, Access does support stored procedures but you have to create and edit them by hand. Meaning, you'd have to run a command like "CREATE PROCEDURE test1..." for Access to create it. AFAIK, there is no GUI front end to do this with Access itself. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
cmaras Posted November 3, 2003 Author Posted November 3, 2003 Thanks for the info "Nerseus".. Claudio 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.