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. General Programming
  3. C#
  4. inserting data thru forms

inserting data thru forms

Scheduled Pinned Locked Moved C#
csharpdatabaseasp-netsql-serversysadmin
3 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.
  • K Offline
    K Offline
    Kunal P
    wrote on last edited by
    #1

    hey i am developing a web application using asp.net, but coding in C#. i need to insert into my database (sql server 2000/access). how shud i do it. i have two textboxes.. watever the user enters in it, it shud be added in a particular table.

    Kunal Piyush

    S 1 Reply Last reply
    0
    • K Kunal P

      hey i am developing a web application using asp.net, but coding in C#. i need to insert into my database (sql server 2000/access). how shud i do it. i have two textboxes.. watever the user enters in it, it shud be added in a particular table.

      Kunal Piyush

      S Offline
      S Offline
      signbit
      wrote on last edited by
      #2

      You take the values and run the query through an SQLCommand Object, that's the simplest solution...

      - A programmer's national anthem; "AAAAAHHHHH!!!!"

      K 1 Reply Last reply
      0
      • S signbit

        You take the values and run the query through an SQLCommand Object, that's the simplest solution...

        - A programmer's national anthem; "AAAAAHHHHH!!!!"

        K Offline
        K Offline
        Kunal P
        wrote on last edited by
        #3

        i coded a bit.. but now sql database i showing an error if i keep the field "Username" as a primary key. firstly the data is entered in a very ad-hoc fashion.. there is a row empty at the top...data entered in between two rows which are already filled with data.. and if i delete some data,then i get the error as "Another user has modified the contents of the table,the database row ur modifying no longer exists in the database....... violation of PRIMARY KEY constraint...." THE CODE:- try { SqlConnection conn = new SqlConnection("server=(local);" + "database=path;" + "connection timeout=3;" + "Trusted_Connection=yes;" + "Integrated Security=true;" + "user id=sa;" + "password="); conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "Insert into login(Username,Password) values('"+uname.Text+"','"+pass.Text+"')" ; SqlDataReader dread = cmd.ExecuteReader(); if (dread.Read()) { failed.Text = "Could not add the user"; } else { Response.Redirect("success.aspx"); } conn.Close(); } catch(Exception kp) { failed.Text=kp.Message; } }

        Kunal Piyush

        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