ХТМЛ:
- Код: Выделить всё
<html>
<head>
</head>
<body>
<form runat="server">
<p>
Регистрация
</p>
<p>
<table style="WIDTH: 300px; HEIGHT: 90px" height="90" width="300">
<tbody>
<tr>
<td>
Желаемый логин:</td>
<td>
<asp:TextBox id="Login" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Пароль:</td>
<td>
<asp:TextBox id="Password" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Подтверждение пароля:</td>
<td>
<asp:TextBox id="Password1" runat="server"></asp:TextBox>
</td>
</tr>
</tbody>
</table>
</p>
</form>
<p>
<asp:Button id="Register" onclick="Register_Click" runat="server" Text="Регистрация" ToolTip="Ну жми скорее :-)"></asp:Button>
<asp:Label id="MSG" runat="server"></asp:Label>
</p>
</body>
</html>
Сам код приложения
- Код: Выделить всё
Function MyQueryMethod(ByVal login As String) As System.Data.IDataReader
Dim connectionString As String = "server='(local)'; trusted_connection=true; database='MyTestBase'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "SELECT [Users].[Login] FROM [Users] WHERE ([Users].[Login] = @Login)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_login As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_login.ParameterName = "@Login"
dbParam_login.Value = login
dbParam_login.DbType = System.Data.DbType.StringFixedLength
dbCommand.Parameters.Add(dbParam_login)
dbConnection.Open
Dim dataReader As System.Data.IDataReader = dbCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
Return dataReader
End Function
Function MyInsertMethod(ByVal name As String) As Integer
Dim connectionString As String = "server='(local)'; trusted_connection=true; database='MyTestBase'"
Dim dbConnection As System.Data.IDbConnection = New System.Data.SqlClient.SqlConnection(connectionString)
Dim queryString As String = "INSERT INTO [Users] ([Name], [Login], [Password], [Privileges]) VALUES (@Name, En"& _
"teredLogin, EnteringPassword, 1)"
Dim dbCommand As System.Data.IDbCommand = New System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
Dim dbParam_name As System.Data.IDataParameter = New System.Data.SqlClient.SqlParameter
dbParam_name.ParameterName = "@Name"
dbParam_name.Value = name
dbParam_name.DbType = System.Data.DbType.String
dbCommand.Parameters.Add(dbParam_name)
Dim rowsAffected As Integer = 0
dbConnection.Open
Try
rowsAffected = dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try
Return rowsAffected
End Function
Sub Register_Click(sender As Object, e As EventArgs)
if (Login.Text="")
MSG.Text="Вы должны ввести логин"
else
if (Password.Text="")
MSG.Text="Введите пароль"
else
if (Password1.Text="")
MSG.Text="Подтвердите пароль"
else
if (login.Text is MyQueryMethod(Login.Text))
MSG.Text="Этот логин уже существует"
end if
end if
end if
end if
End Sub
Не понимаю причем тут runat="server"