Visual Studio 2005 database programming?

How will i write a code if i want the data that i enter in the text box to be inserted in MS Access 2002/2003 and aso able to get the data for viewing, what I did is that I created 2 text box 1. for the FirstName 2. for the last name…then i created 2 buttons 1 for ok/update 2. for Cancel/Close what i want is if i Click “Ok/Update” button i want the my entries in the 2 txt back to be in the MS Access…and Also if i want to recover them for viewing purposes…And also how can i handle if the names is already in the database…say i want to display an error “Name Already Exist” then will have “ok” button.
This are the name that i set using Visual basic 2005
Txtbox 1 name: txtFName
Txtbox 1 name: txtLName
Ok/Update button name: btnOk
Cancel button name: btnCanc

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Tags: ,

This entry was posted on Saturday, July 17th, 2010 at 9:50 pm and is filed under Visual studio database. You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.

One Response to “Visual Studio 2005 database programming?”

  1. Kevin Says:

    hi.. this is good question

    in order to resolve this problem one of the possible way is

    executing a select statement before doing the insertion in the database

    create connection to the database…

    so ur getting the first and last name in the text box

    Execute the following query: (use datareader to execute the query)

    “select * from Employee where Fname = ‘” & txtFName.text & “‘ and LName = ‘” & txtLName & “‘”

    after executed the query using VS2005 in the execute reader

    check

    if dr.hasrows() = true
    Msgbox(“Name already exist”)
    else

    endif

    so u can prevent the duplication of the first and last name
    if u want check only the first or last name provide that one in the select query which u want to check

    sample Example: for checking username and password

    dim theOleDbCommand = new OleDbCommand(“SELECT [ID] FROM tableName WHERE username = ‘” + this.txtUserName.Text + “‘ AND [Password] = ‘” + this.txtPassword.Text + “‘”);

    theOleDbCommand.Connection = new OleDbConnection(connectionStringHere);

    theOleDbCommand.Connection.Open();

    dim theReader = theOleDbCommand.ExecuteReader(CommandBehavior.CloseConnection);

    //you may need to comment out the line below, experiment:

    //theReader.Read();

    if (theReader.HasRows) then
    {

    //they logged in, data exists

    }

    else

    {

    //error, they don’t exist or the username/password is invalid

    }

    theOleDbCommand.Connection.Close();

Leave a Reply

 

About - Contact - Privacy Policy - Terms of Service