ASP.NET, referring to a DataSet within script

Reply

Join Date: Dec 2004
Posts: 2
Reputation: fortheloveof is an unknown quantity at this point 
Solved Threads: 0
fortheloveof's Avatar
fortheloveof fortheloveof is offline Offline
Newbie Poster

ASP.NET, referring to a DataSet within script

 
0
  #1
Dec 28th, 2004
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?

  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2
Reputation: fortheloveof is an unknown quantity at this point 
Solved Threads: 0
fortheloveof's Avatar
fortheloveof fortheloveof is offline Offline
Newbie Poster

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

 
0
  #2
Dec 28th, 2004
...well I solved that one.

The necessary code was simply this:
  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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC