Pakistan IT Forum (Discuss Information Technology in Pakistan)
News: Boards and Categories have been modified. Please post your Feedbacks and Suggestions.
 
*
Hi, Guest. Welcome to IT Forum of Pakistan, Please login or register. November 21, 2008, 07:10:09 AM


Login with IT Forum's username, password and session length


Pak IT forum is launched to provide Pakistan's IT community with a platform to discuss IT related issues. These IT related discussions are proved to be useful for other Pakistani people. Information Technology in Pakistan is hottest issue on IT related forums. We hope that serious Pakistani people will join this IT Forum and will let us know about their experience in order to boast Pakistan's Software Exports.

Pages: [1]
  Print  
Author Topic: how to check the username is already exist in a table...?  (Read 362 times)
asad_black
Newbie
*
Posts: 1


View Profile
« on: September 11, 2008, 12:30:37 AM »

hi every one...!

em creating a create user account page.

i want to check the username is already exists in my database table or not?

if exists then give me a error message that username is already exists if not then account will be successfully create.

em using this code but its not work correctly..

i dont know whatz de problem. and please remember em using Access database.

please point out my mistakes.





<script language="VB" runat="server">
Dim objConnection As OleDbConnection
Sub Page_Load(Source As Object, E As EventArgs)
objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " _
& "DATA SOURCE=" _
& Server.MapPath("nwind.mdb;"))
End Sub




Sub btnInsert_Click(ByVal Sender As Object, ByVal E As EventArgs)

Dim query As String
query = "Select Count(*) From login Where username = ? "
Dim result As Integer = 0

If result > 0 Then



Dim strSQL As String = "INSERT INTO login (username, [password]) " & _
"VALUES (?, ?) "


Dim dbComm As New OleDbCommand(strSQL, objConnection)
dbComm.Parameters.Add("UserName", OleDbType.VarChar, 32, "UserName")
dbComm.Parameters.Add("Password", OleDbType.VarChar, 128, "Password")

dbComm.Parameters("UserName").Value = txtUserName.Text
dbComm.Parameters("Password").Value = txtPassword.Text

Try
objConnection.Open()
dbComm.ExecuteNonQuery()
Catch ex As Exception
Response.Write(ex.Message)
Response.End()
Finally
If objConnection.State = ConnectionState.Open Then
objConnection.Close()
End If
End Try

Response.Write("A new record has been added")
Response.End()


Else
Response.Write("your username is already exist")
End If


End Sub

</script>
Logged
Pages: [1]
  Print  
 
Jump to:  


Powered By: comsdev Partners