(VB)Updating row data in SQL

Hey guys,

I have a small issue doing the following.

Before inserting rows into a table I need to make sure that the rows is not already there.. If they are, I want to update the rows, else insert new rows ..

I have the inserting of new rows figured out, but can't figure out how to check if the row is already there .. This is where I need your help..

Thanks,
Nilysg



Answer this question

(VB)Updating row data in SQL

  • VoiceOfExperience

    Hey DMan,

    This were exactly what I were looking for :) (Can't believe how much time I used searching for something this simple)

    Thanks alot,
    Nilysg


  • Arjun B

    Hmm... I redraw my "simple" statement for now ..

    Code:

    Private Sub AddHublist(ByRef sMyinfo As String)
    Dim s() As String = sMyinfo.Split("|", 7, StringSplitOptions.None) 'parse
    Dim Dr As DataRow = DixwebDataSet.Hubs.Rows.Find(s(2)) '<----Table doesn't have a primary key.

    If Not IsNothing(Dr) Then

    ----------------------------------------------------
    I've set the first row as Primary Key (done from SQL Mangement Studio)
    Do I have to do anything else to make it "show up" as primary

    Thanks,
    Nilysg


  • Peter Mackay

    pseduo code

    Dim Dr As DataRow = DataTable.Rows.Find("PrimaryKeyValue")

    If IsNothing(Dr) Then

    InsertRow(Dr)

    Else

    UpdateItem(Dr)

    End If



  • (VB)Updating row data in SQL