944,089 Members | Top Members by Rank

Ad:
  • ASP Discussion Thread
  • Unsolved
  • Views: 5705
  • ASP RSS
Dec 28th, 2004
0

ASP.NET, referring to a DataSet within script

Expand Post »
I am using ASP.NET, and the ASP.NET WebMatrix program, latest version. I am writing a page that is supposed to check the username someone has entered into a textbox against the list of users from the database, so that two people can't have the same username. Simple, right? Not when you're me.

I know what I'd like to do, I just have no idea how to write the following in ASP.NET. This is the pseudo-code for it.
"If txtUserName.Text = Currently Selected Record.Username then"

I can put a <asp:repeater> in the code and use <%#Container.DataItem("Username")%> to print the Username which is great, but that doesn't work within the <script> tags at the top of the page. I just want to know how to refer to the records I've just loaded. What is it called?

Also, what is the difference between a dataSet and a dataReader?

ASP Syntax (Toggle Plain Text)
  1. Function GetCustomerList() As System.Data.IDataReader
  2. Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=" & server.mappath("db\super.mdb")
  3. Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)
  4. Dim strUN
  5.  
  6. Dim queryString As String = "SELECT Customer.Username FROM Customer"
  7. Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
  8. dbCommand.CommandText = queryString
  9. dbCommand.Connection = dbConnection
  10.  
  11. dbConnection.Open
  12. Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
  13.  
  14. Return dataReader
  15. End Function
  16.  
  17. Sub cmdSubmit_Click(sender As Object, e As EventArgs)
  18. GetCustomerList()
  19. If txtUserName.Text = !!!WHAT! WHAT do I have to do here!!! Then
  20. lblUsed.Text = "That username is in use. Please choose another."
  21. else
  22. lblUsed.Text = "OK"
  23. end if
  24. End Sub

Many thanks for your help. This is totally frustrating.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fortheloveof is offline Offline
2 posts
since Dec 2004
Dec 28th, 2004
0

Re: ASP.NET, referring to a DataSet within script

...well I solved that one.

The necessary code was simply this:
ASP Syntax (Toggle Plain Text)
  1. While dataReader.Read()
  2. if dataReader("Username") = txtUsername.Text then
  3. label1.Text = "Username is already taken!"
  4. end if
  5. End While
This .Read() fiasco apparently replaced the old .MoveNext from regular ASP. When there are items left, .Read() will return "True". Otherwise, i.e. when there are no more records, it will return "False"... hence the while loop.

This is why I hate computers.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
fortheloveof is offline Offline
2 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP Forum Timeline: ASP, Java and XML-RPC
Next Thread in ASP Forum Timeline: asp sales report





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC