Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating table using Dataset doesn't work

Status
Not open for further replies.

konLao

Programmer
Mar 10, 2003
61
US
Hi all,

What's wrong with my code. I have table containing list of books with ISBN numbers. I used these ISBN numbers to go get other related informations and update my SQL table. The problem is it doesn't update my SQL table when it execute line...
Code:
objAdapter.Update(objDataSet, "DS_Books")
.

I used MS-SQL 2k, Studio .NET 2003, WinXP. AGENT!

Code:
Function GetTableData() As Boolean
        Dim objConnection As New SqlConnection("server=SammyNoteBook;uid=sa;pwd=sa;database=Book")
        Dim strSQL As String

        strSQL = "SELECT ISBN,Title,Publisher,Dimension,Weight,FoundNot FROM tblISBN "
        strSQL = strSQL & "WHERE (NOT (ISBN = '')) AND ((Title IS NULL) OR (Title = '') OR "
        strSQL = strSQL & "(Publisher IS NULL) OR (Publisher = '') OR (Dimension IS NULL) OR (Dimension = '') OR "
        strSQL = strSQL & "(Weight IS NULL) OR (Weight = '')) ORDER BY ISBN"

        Dim objAdapter As New SqlDataAdapter(strSQL, objConnection)

        Dim objDataSet As DataSet = New DataSet
        Dim objRow As DataRow
        Dim lnCount As Integer
        Dim lnTotalCount As Integer
        Dim strISBN As String

        objAdapter.Fill(objDataSet, "DS_Books")
        objConnection.Open()

        For Each objRow In objDataSet.Tables(0).Rows

            strISBN = objRow("ISBN")

            objRow("Title") = getTitle(objRow("ISBN"))
            objRow("Publisher") = GetPublisher(objRow("ISBN"))
            objRow("Dimension") = getDimension(objRow("ISBN"))
            objRow("Weight") = getWeight(objRow("ISBN"))
            objRow("FoundNot") = getFoundNot(objRow("ISBN"))

            objAdapter.UpdateCommand = New SqlCommand("spUpdateBooks", objConnection)
            objAdapter.UpdateCommand.CommandType = CommandType.StoredProcedure
            objAdapter.UpdateCommand.Parameters.Add(New SqlParameter("@ISBN", SqlDbType.Char, 27, objRow("ISBN")))
            objAdapter.UpdateCommand.Parameters.Add(New SqlParameter("@Title", SqlDbType.Char, 100, objRow("Title")))
            objAdapter.UpdateCommand.Parameters.Add(New SqlParameter("@Publisher", SqlDbType.Char, 100, objRow("Publisher")))
            objAdapter.UpdateCommand.Parameters.Add(New SqlParameter("@Dimension", SqlDbType.Char, 25, objRow("Dimension")))
            objAdapter.UpdateCommand.Parameters.Add(New SqlParameter("@Weight", SqlDbType.Char, 10, objRow("Weight")))
            objAdapter.UpdateCommand.Parameters.Add(New SqlParameter("@FoundNot", SqlDbType.Char, 3, objRow("FoundNot")))

            'Next line suppose to be updating my table but it's not
            objAdapter.Update(objDataSet, "DS_Books")
        Next

        objConnection.Close()

    End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top