Pretty obvious, I'd say... because you have completely forgotten to
supply your SqlDataSource with any Parameters.
On Dec 6, 9:42 am, nag <[EMAIL PROTECTED]> wrote:
> i am getting the following error while inserting record to db
> Object reference not set to an instance of an object.
> Line 70: this.SqlDataSource1.InsertParameters
> ["projectname"].DefaultValue = companyName.Text;
> here is my code plz anyone help me
> <ctMenu:ContextMenu ID="ContextMenu1" runat="server"
> BackColor="#99CCCC" ForeColor="Maroon"
> OnItemCommand="ContextMenu1_ItemCommand"
> RolloverColor="#009999" Width="111px" />
>
> <asp:SqlDataSource ID="SqlDataSource1" runat="server"
> ConnectionString="<%$
> ConnectionStrings:durvaaConnectionString %>"
> SelectCommand="SELECT * FROM [dg_project]">
> </asp:SqlDataSource>
>
> <xGrid:xGrid ID="XGrid1" runat="server" AllowPaging="True"
> AutoGenerateColumns="False" DataKeyNames="projectid"
> CellPadding="4" AllowSorting="True" BackColor="White"
> BorderColor="#3366CC" BorderStyle="None"
> BorderWidth="1px" OnRowDeleting="XGrid1_RowDeleting"
> MouseOverColor="0, 153, 153" OnFilterCommand="XGrid1_FilterCommand"
> ContextMenuID="ContextMenu1" DescImage="~/App_Images/desc.gif"
> AscImage="~/App_Images/asc.gif" OnRowClick="XGrid1_RowClick"
> OnRowDoubleClick="XGrid1_RowDoubleClick" IsFiltered="True"
> EnableRowClick="True">
> <Columns>
> <asp:TemplateField HeaderText="Manage Row">
> <edititemtemplate>
> <asp:LinkButton text="Update" runat="server"
> id="lnkUpdate" CommandName="Update" CommandArgument='<% Bind
> ("projectname") %>' />
> <asp:LinkButton text="Cancel" runat="server"
> id="lnkCancel" CommandName="Cancel" />
>
> </edititemtemplate>
> <footertemplate>
> <confirmControl:ConfirmLinkButton ID="lnkAdd"
> runat="server" Text="Add" MessageText="Are you sure you want to add
> this record?" OnClick="btnAdd_Click" />
> <asp:LinkButton id="lnkCancelAdd"
> runat="server" text="Cancel" OnClick="btnCancel_Click" />
>
> </footertemplate>
> <itemtemplate>
> <asp:LinkButton id="lnkEdit" runat="server" __designer:wfdid="w1"
> text="Edit" CommandName="Edit" CommandArgument='<% Bind("projectid")
> %>'></asp:LinkButton> <confirmControl:ConfirmLinkButton
> id="lnkDelete" runat="server" __designer:wfdid="w2"
> CommandName="Delete" CommandArgument='<% Bind("projectid") %>'
> Text="Delete" MessageText="Are you sure you want to delete this
> record?"></confirmControl:ConfirmLinkButton>
> </itemtemplate>
> </asp:TemplateField>
>
> <asp:TemplateField HeaderText="Company Name"
> SortExpression="projectname">
> <edititemtemplate>
> <asp:TextBox id="txtEditCompanyName"
> runat="server" Text='<%# Bind("projectname") %>'></asp:TextBox>
>
> </edititemtemplate>
> <footertemplate>
> <asp:TextBox ID="txtCompanyName"
> runat="server" />
>
> </footertemplate>
> <itemtemplate>
> <asp:Label ID="lblCompanyName" runat="Server"><
> %# Eval("projectname") %></asp:Label>
>
> </itemtemplate>
> </asp:TemplateField>
> </Columns>
>
> <FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
> <RowStyle BackColor="White" ForeColor="#003399" />
> <SelectedRowStyle BackColor="#009999" Font-Bold="True"
> ForeColor="#CCFF99" />
> <PagerStyle BackColor="#99CCCC" ForeColor="#003399"
> HorizontalAlign="Left" />
> <HeaderStyle BackColor="#003399" Font-Bold="True"
> ForeColor="#CCCCFF" />
> <FilterStyle BackColor="#003399" ForeColor="#CCCCFF" Font-
> Size="8pt" />
> <EmptyDataTemplate>
> No Data Available
> </EmptyDataTemplate>
> </xGrid:xGrid>
>
> protected void btnAdd_Click(object sender,EventArgs e)
> {
> TextBox companyName = this.XGrid1.FooterRow.FindControl
> ("txtCompanyName") as TextBox;
> this.SqlDataSource1.InsertParameters
> ["projectname"].DefaultValue = companyName.Text;
> this.SqlDataSource1.Insert();
> this.XGrid1.ChangeInsertMode(false);
> }