User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 426,256 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,071 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting

VB.net/ASP.net SELECT problems with SQL

Join Date: Mar 2008
Location: Wales
Posts: 30
Reputation: BluePaper is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
BluePaper's Avatar
BluePaper BluePaper is offline Offline
Light Poster

VB.net/ASP.net SELECT problems with SQL

  #1  
Mar 27th, 2008
Mhm. This is the VB.net code behind a webpage I'm working with, I've also provided the ASP.net for the frontpage as well. This maybe really simple and I've missed it but everytime I run this code (below) I keep on getting the same error "Invalid column name, Skyrail" where 'Skyrail' is the data in one of the field names (the user alias field). So here's my VB.net code:

  1.  
  2. 'Import the required things
  3. Imports System.Data, System.Data.SqlClient
  4. Class _Default
  5. Inherits System.Web.UI.Page
  6. 'Set the variables
  7. Dim SQLConnectionString As String
  8. Dim SQLConnectionStatus As String = "Closed"
  9. Dim SQLConnection As New SqlConnection()
  10. Dim SQLCommand As New SqlCommand()
  11. Dim SQLData As SqlDataReader
  12. 'Function used to open up the SQL connection
  13. Function sqlDBConnection() As Object
  14. 'Create the Connection String
  15. SQLConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\Owner\My Documents\Visual Studio 2008\WebSites\Overland\App_Data\Overland.mdf;Integrated Security=True;User Instance=True"
  16. 'Set the connection string into the SQL connection
  17. SQLConnection.ConnectionString = SQLConnectionString
  18. 'Open up the connection
  19. SQLConnection.Open()
  20. 'Check to see if it was succesful
  21. If SQLConnection.State = ConnectionState.Open Then
  22. 'If so tell them so
  23. ValidationWarning.Text = "Success!"
  24. 'Set the connection status to open
  25. SQLConnectionStatus = "Open"
  26. End If
  27. 'Return the connection status
  28. Return SQLConnectionStatus
  29. End Function
  30. 'Function used to close the SQL connection
  31. Function sqlDBConnectionClose() As Object
  32. 'Close the connection
  33. SQLConnection.Close()
  34. 'Check to see if it's still open
  35. If SQLConnection.State = ConnectionState.Open Then
  36. 'If it is tell them that the database closing failed
  37. ValidationWarning.Text = "Failed closing database!"
  38. 'Keep the connection status as open
  39. SQLConnectionStatus = "Open"
  40. Else
  41. 'Else the connection isn't open so tell them
  42. ValidationWarning.Text = "Connection Closed"
  43. 'Set the connections status as closed
  44. SQLConnectionStatus = "Closed"
  45. End If
  46. 'Return the connection status
  47. Return SQLConnectionStatus
  48. End Function
  49.  
  50. 'The sub procedure that validates the boxes
  51. Protected Sub ValidateInput_Command(ByVal sender As Object, ByVal e As System.EventArgs) Handles ValidateInput.Command
  52. 'Check to see if any of the fields are empty
  53. If UserAlias.Text.Length = 0 Or UserName.Text.Length = 0 Or UserPass.Text.Length = 0 Then
  54. 'Tell them that they've left a field or two empty
  55. ValidationWarning.Text = "You left a field blank!"
  56. 'Ensure that the two passwords are equal
  57. ElseIf UserPass.Text <> UserPassCheck.Text Then
  58. 'If they don't tell them that
  59. ValidationWarning.Text = "You're passwords didn't match"
  60. 'Check to see if the password length is above 6
  61. ElseIf UserPass.Text.Length < 6 Then
  62. 'If not tell them that it's too short
  63. ValidationWarning.Text = "You're password is too short!"
  64. Else
  65. 'We're going to try and open a database connection
  66. Try
  67. 'Try and open it
  68. sqlDBConnection()
  69. 'Catch any exceptions
  70. Catch exception As System.Exception
  71. 'Tell them that it failed and for my use why
  72. ValidationWarning.Text = "Could not connect to the database" & exception.Message
  73. 'MsgBox(exception.Message, MsgBoxStyle.Critical, "Exception Error")
  74. End Try
  75. 'If the connection was succesful
  76. If SQLConnectionStatus = "Open" Then
  77. 'Then we're going to check if the user already exists - doesn't actually work...at all
  78. Dim SQLCheckForUser As String = "SELECT * FROM Users WHERE UserAlias = " & UserAlias.Text
  79. SQLCommand.Connection = SQLConnection
  80. SQLCommand.CommandText = SQLCheckForUser
  81. SQLCommand.ExecuteNonQuery()
  82. SQLData = SQLCommand.ExecuteReader
  83. If SQLData.Read() Then
  84. ValidationWarning.Text = "Found the user already?"
  85. End If
  86. End If
  87. End If
  88. End Sub
  89. 'The sub procedure that closes the connection
  90. Protected Sub CloseConnection_Command(ByVal sender As Object, ByVal e As System.EventArgs) Handles CloseConnection.Command
  91. 'The function that closes the connection
  92. sqlDBConnectionClose()
  93. End Sub
  94. End Class
  95.  

And here is my ASP.net page (.aspx, minus the CSS_

  1.  
  2. <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
  3.  
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  5.  
  6. <html xmlns="http://www.w3.org/1999/xhtml">
  7. <head runat="server">
  8. <title>Overland</title>
  9. <style type="text/css">
  10. ...
  11. </style>
  12. </head>
  13. <body>
  14. <form runat="server" id="HomePage">
  15.  
  16. <div class="Surround">
  17.  
  18. <div class="Navigation">
  19.  
  20. </div>
  21.  
  22. <div class="Content">
  23.  
  24. <h1>Overland</h1>
  25. <fieldset>
  26. <label for="UserAlias">User Alias:</label>
  27. <p><asp:TextBox MaxLength="20" ID="UserAlias" runat="server" class="textbox" /></p>
  28. <label for="UserName">Real Name:</label>
  29. <p><asp:TextBox MaxLength="30" ID="UserName" runat="server" class="textbox" /></p>
  30. <label for="UserPass">Password:</label>
  31. <p><asp:TextBox MaxLength="50" TextMode="Password" ID="UserPass" runat="server" class="textbox" /></p>
  32. <label for="UserPassCheck">Password (again):</label>
  33. <p><asp:TextBox MaxLength="50" TextMode="Password" ID="UserPassCheck" runat="server" class="textbox" /></p>
  34. <asp:Button Text="Validate" ID="ValidateInput" runat="server"/>
  35. <asp:Button Text="Close Connection" ID="CloseConnection" runat="server" />
  36. <p><asp:Label ID="ValidationWarning" runat="server" Text="" /></p>
  37. </fieldset>
  38.  
  39. </div>
  40.  
  41. </div>
  42. </form>
  43. </body>
  44. </html>


It's a simple page and currently I'm just messing around/testing. What I'm trying to do is a mockup registration page for a simple user system, it's breaking in the VB.net where I am trying to check whether the user exists already by using a SELECT query: Dim SQLCheckForUser As String = "SELECT * FROM Users WHERE UserAlias = " & UserAlias.Text .

Another problem with this code is that once I've fixed the SELECT query to work how can I check if it actually found anybody?

Thanks for your time.
Last edited by BluePaper : Mar 27th, 2008 at 1:12 pm. Reason: Wrong code syntax picked.
Stone In Focus - Caffeine Group - CoffeePHP - Open Notes - Onyx - Redpoint Network - Espresso
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 9:08 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC