Dataset Designer problems

Discussion in 'ASP .Net' started by SAL, Mar 16, 2007.

  1. SAL

    SAL Guest

    I'm curious if anyone else is having this problem. If I let the Dataset
    designer generate update commands for me, I don't seem to be able to get
    them to work without an exception getting thrown, (Update requires a valid
    UpdateCommand), but if I execute the following code it does work. It seems
    like a total waste of time to have to write the following code if the
    dataset designer can generate the code:

    Dim annexs As New SqlDataAdapter
    Dim sql As String = "SELECT DateReceived, Name, EstimatedTaxImpacts, " & _
    "EstimatedAssessedValue, GSReview, StatuteId, " & _
    "StatuteRequirementsMet FROM Annexations " & _
    "WHERE AnnexationId = " & annexationId.ToString()
    annexs.SelectCommand = New SqlCommand(sql)
    annexs.SelectCommand.CommandType = CommandType.Text
    annexs.SelectCommand.Connection = Adapter.Connection

    Dim ds As DataSet = New DataSet
    annexs.UpdateCommand = New SqlCommand( _
    "UPDATE Annexations SET DateReceived = @dateReceived, Name = @name,
    EstimatedTaxImpacts = " & _
    "@estimatedTaxImpacts, EstimatedAssessedValue = @estimatedAssessedValue,
    " & _
    "GSReview = @gsReview, StatuteId = @statuteId, StatuteRequirementsMet =
    " & _
    "@statuteRequirementsMet WHERE AnnexationId = " & annexationId,
    Adapter.Connection)
    annexs.UpdateCommand.Parameters.Add("@dateReceived", SqlDbType.DateTime)
    annexs.UpdateCommand.Parameters.Add("@name", SqlDbType.VarChar, 25)
    annexs.UpdateCommand.Parameters.Add("@estimatedTaxImpacts",
    SqlDbType.Decimal)
    annexs.UpdateCommand.Parameters.Add("@estimatedAssessedValue",
    SqlDbType.Decimal)
    annexs.UpdateCommand.Parameters.Add("@gsReview", SqlDbType.DateTime)
    annexs.UpdateCommand.Parameters.Add("@statuteId", SqlDbType.Int)
    annexs.UpdateCommand.Parameters.Add("@statuteRequirementsMet",
    SqlDbType.Bit)
    annexs.Fill(ds, "Annexations")
    Dim annex As DataRow
    If ds.Tables(0).Rows.Count > 0 Then
    annex = ds.Tables(0).Rows(0)
    Else
    Return False
    End If
    If dateReceived.HasValue Then
    annexs.UpdateCommand.Parameters("@dateReceived").Value =
    dateReceived.Value
    End If
    With annex
    annexs.UpdateCommand.Parameters("@name").Value = name
    If Not estimatedTaxImpacts.HasValue Then
    annexs.UpdateCommand.Parameters("@estimatedTaxImpacts").Value =
    DBNull.Value
    Else
    annexs.UpdateCommand.Parameters("@estimatedTaxImpacts").Value =
    estimatedTaxImpacts.Value
    End If
    If Not estimatedAssessedValue.HasValue Then
    annexs.UpdateCommand.Parameters("@estimatedAssessedValue").Value =
    DBNull.Value
    Else
    annexs.UpdateCommand.Parameters("@estimatedAssessedValue").Value =
    estimatedAssessedValue.Value
    End If
    If gsReview.HasValue Then
    annexs.UpdateCommand.Parameters("@gsReview").Value = gsReview.Value
    Else
    annexs.UpdateCommand.Parameters("@gsReview").Value = DBNull.Value
    End If
    annexs.UpdateCommand.Parameters("@statuteId").Value = statuteId.Value
    annexs.UpdateCommand.Parameters("@statuteRequirementsMet").Value =
    statuteRequirementsMet
    End With
    Dim affectedrows As Integer = annexs.Update(ds, "Annexations")
     
    SAL, Mar 16, 2007
    #1
    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. GS
    Replies:
    1
    Views:
    2,678
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Jan 19, 2006
  2. John Dalberg
    Replies:
    0
    Views:
    458
    John Dalberg
    Mar 23, 2006
  3. Steve B.
    Replies:
    4
    Views:
    974
    Cheryl D Wise
    Jun 1, 2007
  4. Alexander Higgins
    Replies:
    3
    Views:
    1,084
    Teemu Keiski
    Jul 30, 2007
  5. Alexander Higgins
    Replies:
    0
    Views:
    452
    Alexander Higgins
    Jul 21, 2007
Loading...

Share This Page