Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Same Username

Same Username

Scheduled Pinned Locked Moved Database
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dayekh
    wrote on last edited by
    #1

    Hi, I want to prevent the admin from being able to store 2 user records which both have the same username. So far, I have pupulated a Dataset variable with the details, but I am unable to work it into an IF statement. Any suggestions?? Thank you

    M 1 Reply Last reply
    0
    • D Dayekh

      Hi, I want to prevent the admin from being able to store 2 user records which both have the same username. So far, I have pupulated a Dataset variable with the details, but I am unable to work it into an IF statement. Any suggestions?? Thank you

      M Offline
      M Offline
      Mark J Miller
      wrote on last edited by
      #2

      Have you tried ?: string sql = @' IF NOT EXISTS(SELECT * FROM foo WHERE user = @username) BEGIN INSERT INTO foo (user) VALUES (@username) SET @Success = 1 END ELSE BEGIN SET @Success = 0 END'; bool bSuccess = false; using(SqlConnection conn = new SqlConnection("connection string")){ SqlCommand cmd = new SqlCommand(conn, sql); cmd.Parameters.Add("@username", SqlDbType.Varchar, 50); cmd.Parameters.Add("@Success", SqlDbType.Bit); cmd.Parameters["@username"].Value = DataSet.Tables[0].Rows[0]["Username"]; cmd.Parameters["@Success"].Direction = ParameterDirection.InputOutput; conn.Open(); cmd.ExecuteNonQuery(); bSuccess = (bool) cmd.Parameters["@Success"].Value; } if(!bSucess) { //tell the user }

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups