Issues with OledbDataAdapter.Update()

Discussion in 'ASP .Net' started by amessimon, Apr 30, 2004.

  1. amessimon

    amessimon Guest

    Hi

    I have a problem with an insert statment using the update() method of the
    OledbDataAdapter.
    I'm getting the error 'Update requires a valid InsertCommand when passed
    DataRow collection with new rows. '
    Heres a condensed version of the page.

    <%@ Import Namespace="system.Data" %>
    <%@ Import Namespace="system.Data.Oledb" %>
    <script language="vb" runat="server">
    Sub Page_Load(sender As Object, e As EventArgs)
    Dim objDataSet As New DataSet()
    Dim objDataAdapter As New OledbDataAdapter()
    Dim strConnection As String =
    ConfigurationSettings.AppSettings("ConnectionString")
    Dim strSQL As String = "SELECT [ppcTerm], [pageName], [contentTitle],
    [contentBody] FROM tbl_content"
    Dim objConnection As New oleDbConnection(strConnection)
    Dim objCommand As New oleDbCommand(strSQL, objConnection)
    objDataAdapter.SelectCommand = objCommand
    objDataAdapter.Fill(objDataSet)
    Dim objNewRow As DataRow = objDataSet.Tables(0).NewRow
    objNewRow(0) = "value1"
    objNewRow(1) = "value2"
    objNewRow(2) = "value3"
    objNewRow(3) = "value4"
    objDataSet.Tables(0).Rows.Add(objNewRow)
    objDataAdapter.Update(objDataSet)
    End sub
    </script>

    I'm aware there are other ways of doing this like using an INSERT statement,
    but i'd like to know why this isnt working.

    Thanks for any help in advance.

    Simon Ames
     
    amessimon, Apr 30, 2004
    #1
    1. Advertising

  2. amessimon

    Natty Gur Guest

    Hi,

    Although I'm against using datasets (ORM much better), you need to set
    objDataAdapter.InsertCommand exectly as you set SelectCommand. Otherwise
    the adapter won't know which command to run against changed values in
    dataset.

    HTH

    Natty Gur[MVP]

    blog : http://weblogs.asp.net/ngur
    Mobile: +972-(0)58-888377


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
     
    Natty Gur, May 2, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. darrel

    OleDbDataAdapter vs OleDbCommand

    darrel, Nov 23, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    7,036
    Scott M.
    Nov 25, 2005
  2. Bennett Haselton
    Replies:
    1
    Views:
    3,421
    Bennett Haselton
    Oct 18, 2004
  3. joun
    Replies:
    9
    Views:
    2,280
    W.G. Ryan eMVP
    Nov 30, 2004
  4. joun
    Replies:
    5
    Views:
    2,707
  5. tom c
    Replies:
    6
    Views:
    525
    tom c
    Sep 6, 2006
Loading...

Share This Page