Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi folks,

 

I'm getting an error when I attempt to edit a record in my datagrid through a dataset. I'm able to load the grid and select the edit link button which brings the record in Edit mode. In my dataset, I have two dataadapters (one with employee information and another with Job descriptions) that I use to display employee information and the employee Job in the grid. The employee info is in the grid, the job description is a label in a template column. So for a particular employee, you see information and then his Job description as opposed to the jobid on the employee table.

Once the record goes into Edit mode, the job description label becomes a drop down list with a list of all possible Job descriptions, and the employees current job description selected. When I click the Update link button, I get the following error:

 

Prepared statement '(@JobID int, @JobDescr varchar(50), @Original_JobID int, @Original_' expects parameter @JobDescr, which was not supplied.

 

The source error shows the following line as the error:

sqldataadapter1.update(DsJobsEdit1, "employees")

 

 

Here is my code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       'Put user code to initialize the page here
       If Not Page.IsPostBack Then
           SqlConnection1.Open()

           SqlDataAdapter1.Fill(DsJobsEdit1, "jobs")
           SqlDataAdapter2.Fill(DsJobsEdit1, "employees")

           dgEditGrid.DataBind()
       End If
   End Sub

   Public Function BindJob(ByVal o As Object) As String
       Dim drv As DataRowView = o
       Dim dr As dsJobsEdit.EMPLOYEESRow = drv.Row
       Return dr.JOBSRow.JobDescr

   End Function

   Private Sub reBind()

       SqlDataAdapter1.Fill(DsJobsEdit1, "jobs")
       SqlDataAdapter2.Fill(DsJobsEdit1, "employees")
       dgEditGrid.DataBind()

   End Sub

   Public Sub EditCommand(ByVal Sender As Object, ByVal e As DataGridCommandEventArgs)
       dgEditGrid.EditItemIndex = e.Item.ItemIndex
       reBind()

   End Sub

   Public Sub DeleteCommand(ByVal Sender As Object, ByVal e As DataGridCommandEventArgs)
       dgEditGrid.EditItemIndex = -1
       reBind()

   End Sub

   Public Sub CancelCommand(ByVal Sender As Object, ByVal e As DataGridCommandEventArgs)
       dgEditGrid.EditItemIndex = -1
       reBind()

   End Sub

   Public Sub UpdateCommand(ByVal Sender As Object, ByVal e As DataGridCommandEventArgs)
       reBind()
       Dim dr As dsJobsEdit.EMPLOYEESRow = DsJobsEdit1.EMPLOYEES.Item(e.Item.DataSetIndex)
       Dim ddljobs As DropDownList
       ddljobs = e.Item.FindControl("ddlbJobs")
       dr.JobID = ddljobs.SelectedItem.Value
       SqlDataAdapter1.Update(DsJobsEdit1, "employees")
       dgEditGrid.EditItemIndex = -1
       reBind()
   End Sub

   Public Sub ItemDataBound(ByVal Sender As Object, ByVal e As DataGridItemEventArgs)
       Dim lit As ListItemType = e.Item.ItemType
       If lit = ListItemType.EditItem Then
           Dim ddlbjobs As DropDownList
           ddlbjobs = e.Item.FindControl("ddlbjobs")

           Dim drv As DataRowView = e.Item.DataItem
           If Not drv Is Nothing Then
               ddlbjobs.Items.FindByValue(drv("jobid")).Selected = True
           End If
       End If

   End Sub

 

Can anyone please help.

Thanks in advance.

Rick

[edit]Please use

 tags [/ vb][/edit][/color]
Edited by Robby

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...