Insert data = 0
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Insert data = 0

  1. #1
    Join Date
    Sep 2012
    Posts
    16

    Insert data = 0

    I am trying to use Insert Statement which is one of the field(format = Number) in Access = 0. My program does not understand data which is one of the field = 0. Can you help me to solve the problem.

    I am appreciate for your help !!!!!!!
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Insert data = 0

    If it exists, then you cannot insert it. Otherwise, it may start with 1, so I'd try that first.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Sep 2012
    Posts
    16

    Re: Insert data = 0

    I have to insert 2 way : if it exist or not.

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Insert data = 0

    Post your code around the INSERT (and use CODE TAGS, please).
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Sep 2012
    Posts
    16

    Re: Insert data = 0

    Code:
           
     Dim diem as Double
            If (ws.Range("F" & i).Value = NULL) Then
            diem = 0
            Else
            diem = ws.Range("F" & i).Value
            End If
    
            con.Execute "INSERT INTO SV([No],MSSV,MaLop,Ho,Ten,Diem,HanhKiem,[User],Status,[Date]) VALUES ('" & rs("MaxField") + 1 & "','" & ws.Range("C" & i).Value & "','" & ws.Range("A" & i).Value & "','" & ws.Range("D" & i).Value & "','" & ws.Range("E" & i).Value & "','" & ws.Range("F" & i).Value & "','" & tenUser & "','" & "-1" & "','" & NgayGioDangNhap & "')"

  6. #6
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    4,838

    Re: Insert data = 0

    I can't even begin to understand the question, you'll need to do a better job of explaining what you are trying to do and what problem you are having. Also need to tell us what field and what the data type is of that field in the database.
    Always use [code][/code] tags when posting code.

  7. #7
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Insert data = 0

    Try printing the value of the query, and putting that into ACCESS
    Code:
    Dim Query as String
    Query = "INSERT INTO SV([No],MSSV,MaLop,Ho,Ten,Diem,HanhKiem,[User],Status,[Date]) VALUES ('" & rs("MaxField") + 1 & "','" & ws.Range("C" & i).Value & "','" & ws.Range("A" & i).Value & "','" & ws.Range("D" & i).Value & "','" & ws.Range("E" & i).Value & "','" & ws.Range("F" & i).Value & "','" & tenUser & "','" & "-1" & "','" & NgayGioDangNhap & "')"
    Debug.Print Query
    stop
    ' after it works in access, use this:
    
     con.Execute Query ' and it should work
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center