data access question in asp.net 2.0

W

weiwei

Hi,
I have a question regarding data access, here is my scenario, when a
user create username, that username is check against
username table, if new request username is existed already, then return
it to user who originally requested. if that username
is not existed previously, then added it into the database. in
classical asp, I can do that do while...loop + if else
statement. now I am trying to do the .net version, and I am using
visual studio 2005 professional edition.
how can I checking each record in the db table in asp.net? below is my
current code.
thanks in advance!

<%@ Page Language="VB" AutoEventWireup="false"
CodeFile="datatest.aspx.vb" Inherits="datatest" %>
<script runat="server">

Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)

'my connectionstring is already configured in web.config

Dim myConnection As String =
ConfigurationManager.ConnectionStrings("testConnectionString").ConnectionString
Dim strSQL As String = "Select * FROM test"
Dim Connection As New
Data.SqlClient.SqlConnection(myConnection)
Dim myCommand As New Data.SqlClient.SqlCommand(strSQL,
Connection)
Connection.Open()
myCommand.ExecuteNonQuery()
Connection.Close()

End Sub
</script>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<body>

<form id="Form1" runat="server">


</form>

</body>
</html>
 
D

David Wier

select * from tablename where username=@username

Then, if the dataset's table has even 1 row, tell them it's already taken,
and exit out of the sub - but you probably shouldn't have it in the PageLoad
event anyway - have it in another sub and use it whenever someone logs in.

Even still - have you looked into the ASP.Net 2.0 login controls?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top