CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2008
    Posts
    2

    I can not Update database When I want to check Duplicate Records

    Hi There !
    I have a table for e.g. have some here fields
    ------------------------------------------------
    ID FNAME LNAME YearReg RegNo
    ------------------------------------------------
    1 Anna Wacker 1970 108
    2 Antonio Krschne 1970 113
    3 Thomas Edwards 1972 116
    4 Christina Ludick 1970 110
    5 Martin Grilo 1972 102
    -----------------------------------------------
    at the first I want to check in the table if YearReg=1970 , is RegNo is duplicate or not ? and then Update(Edit) the record :
    -----------------------------------------------
    .....
    strSql =@"SELECT RegNo WHERE RegNo=@s1 AND YearReg=1970";
    oda_Edited.SelectCommand.Parameters.AddWithValue(" @s1", txtRegNo.Text);
    .....
    .....
    DataTable dt_Edited = new DataTable();
    dt_Edited.Clear();
    oda_Edited.Fill(dt_Edited);
    if (dt_Edited.Rows.Count > 0)
    {
    MessageBox.Show("Already Exists!! ");
    txtRegNo.Focus();
    }
    else
    {
    OleDbCommand ocmd_Edited02 = new OleDbCommand();
    ocmd_Edited02.CommandText = @"UPDATE myTable SET ....
    ----------------------------------------------------
    But I can not Update the record (message show "Already Exists!!")
    Thanks for any Help ...

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: I can not Update database When I want to check Duplicate Records

    If you are in control of the databse then I will say that you're going about this wrong.

    If a database field is supposed to not contain duplicate values, it should be designed as such. full stop. period. This ensures that the database itself handles these types of situations, instead of us programmers having to paste up all the leaks in our program

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured