lorena
Centurion
I am working with a datagrid that the user (hopefully) will be able to edit/update
The columns are template columns. The grid loads fine but when I change the cell data and click "Update" - I get "Object reference not set to an instance of an object"
Here is the update code:
And part of the datagrid code:
I am just not sure what I am doing wrong.
The columns are template columns. The grid loads fine but when I change the cell data and click "Update" - I get "Object reference not set to an instance of an object"
Here is the update code:
Visual Basic:
Sub dgRecs_UpdateRow(ByVal sender As Object, ByVal e As DataGridCommandEventArgs)
Const strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=\\intranet\databases\toolroom_sched.mdb"
Dim textDwg As TextBox = e.Item.Cells(3).FindControl("txtDwg")
Dim ddlT As DropDownList = e.Item.Cells(2).FindControl("ddlType")
Dim irecordID As Integer
irecordID = dgRecs.DataKeys(e.Item.ItemIndex)
Dim strSQL As String
strSQL = "UPDATE toolroom SET Type = @typeParam, @dwgParam WHERE RecID = @recordIDParam "
Dim objConn As New OleDb.OleDbConnection(strConnString)
Dim objCommand = New OleDb.OleDbCommand(strSQL, objConn)
objConn.Open()
objCommand.CommandType = CommandType.Text
Dim recordIDParam As New OleDb.OleDbParameter("@RecordIDParam", OleDb.OleDbType.Single)
recordIDParam.Value = irecordID
objCommand.Parameters.Add(recordIDParam)
Dim typeParam As New OleDb.OleDbParameter("@typeParam", OleDb.OleDbType.VarChar, 25)
typeParam.Value = ddlT.SelectedItem.Text
objCommand.Parameters.Add(typeParam)
Dim dwgParam As New OleDb.OleDbParameter("@dwgParam", OleDb.OleDbType.VarChar, 25)
dwgParam.Value = textDwg.Text
objCommand.Parameters.Add(dwgParam)
objCommand.ExecuteNonQuery()
objConn.Close()
dgRecs.EditItemIndex = -1
BindData()
End Sub
Code:
<asp:datagrid id="dgRecs" runat="server" AutoGenerateColumns="False" DataKeyField="Rec_ID" OnEditCommand="dgRecs_EditRow" OnUpdateCommand="dgRecs_UpdateRow" OnCancelCommand="dgRecs_CancelRow">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" HeaderText="EDIT" EditText="Edit" UpdateText="Update" CancelText="Cancel"></asp:EditCommandColumn>
<asp:BoundColumn DataField="Rec_ID" HeaderText="Rec ID" ReadOnly="True"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Type">
<ItemTemplate>
<asp:Label Runat="server" id="lblType" Width="60px" text='<%# DataBinder.Eval(Container.DataItem, "Type") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp: DropDownList Runat="server" ID="ddlType" Font-Name="Verdana" Font-Size="xx-small" DataTextField="Type" DataValueField="Type" DataSource="<%# GetTypes() %>">
</asp: DropDownList></EditItemTemplate></asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Dwg No" HeaderStyle-CssClass="tdBasic">
<ItemTemplate>
<asp:Label Runat="server" id="lblDwgNo" Width="60px" Text=' <%# DataBinder.Eval(Container.DataItem, "Dwg_No") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Runat="server" ID="txtDwgNo" Width="100px" Font-Name="Verdana" Font-Size="xx-small" Text='<%# DataBinder.Eval(Container.DataItem, "Dwg_No") %>'>
</asp:TextBox></EditItemTemplate></asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Description">
Last edited by a moderator: