Click here to Skip to main content
15,888,351 members
Home / Discussions / C#
   

C#

 
AnswerRe: Action<T> Delegate usage between 2 applications Pin
HaldorPhil20-Aug-15 6:57
HaldorPhil20-Aug-15 6:57 
Question[SOLVED] SQL Server 2014 & SqlDataSourceEnumerator Pin
MooKowMyke30-May-15 19:14
MooKowMyke30-May-15 19:14 
AnswerRe: SQL Server 2014 & SqlDataSourceEnumerator Pin
MooKowMyke30-May-15 20:37
MooKowMyke30-May-15 20:37 
AnswerRe: SQL Server 2014 & SqlDataSourceEnumerator Pin
Eddy Vluggen31-May-15 0:52
professionalEddy Vluggen31-May-15 0:52 
GeneralRe: SQL Server 2014 & SqlDataSourceEnumerator Pin
MooKowMyke31-May-15 17:20
MooKowMyke31-May-15 17:20 
QuestionHow to change datatype of a variable without changing its value ? Pin
Member 968349129-May-15 22:14
Member 968349129-May-15 22:14 
AnswerRe: How to change datatype of a variable without changing its value ? Pin
OriginalGriff29-May-15 22:59
mveOriginalGriff29-May-15 22:59 
QuestionNot able to insert my data into sql db. Getting that annoying null error! Pin
Norris Chappell29-May-15 7:15
Norris Chappell29-May-15 7:15 
I'm having an issue with my C# code. I m trying to insert data into my database from a form, unfortunately I keep getting issues with Object reference not set to an instance of an object.

Here s the code:
C#
aspx
<asp:GridView runat="server" ID="gvNEW" 
    AutoGenerateColumns="False" BackColor="White" BorderColor="#DEDFDE" 
    BorderStyle="None" BorderWidth="1px" CellPadding="4"
    EnableModelValidation="True" ForeColor="Black" GridLines="Vertical" >
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:TemplateField HeaderText="Name">
            <ItemTemplate>
                <asp:TextBox runat="server" text='<%#Eval("Name") %>' ID="txtName" />
            </ItemTemplate>
        </asp:TemplateField>
         <asp:TemplateField HeaderText="Project">
            <ItemTemplate>
                <asp:TextBox runat="server" text='<%#Eval("Project") %>' ID="txtProject" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Tower">
            <ItemTemplate>
                <asp:TextBox runat="server" text='<%#Eval("Tower") %>' ID="txtTower" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="FunctionalArea">
            <ItemTemplate>
                <asp:TextBox runat="server" text='<%#Eval("FunctionalArea") %>' ID="txtFunctionalArea" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="ResourceName">
            <ItemTemplate>
                <asp:TextBox runat="server" text='<%#Eval("ResourceName") %>' ID="txtResourceName" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="CATWResourceName">
            <ItemTemplate>
                <asp:TextBox runat="server" text='<%#Eval("CATWResourceName") %>' ID="txtCATWResourceName" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Org">
            <ItemTemplate>
                <asp:TextBox runat="server" text='<%#Eval("Org") %>' ID="txtOrg" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="IndicateifbillingFP">
            <ItemTemplate>
                <asp:TextBox runat="server" text='<%#Eval("IndicateifbillingFP") %>' ID="txtIndicateifbillingFP" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="IndicateifbillingTM">
            <ItemTemplate>
                <asp:TextBox runat="server" text='<%#Eval("IndicateifbillingTM") %>' ID="txtIndicateifbillingTM" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="DefaultFTE">
            <ItemTemplate>
                <asp:TextBox runat="server" text='<%#Eval("DefaultFTE") %>' ID="txtDefaultFTE" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Active">
            <ItemTemplate>
                <asp:TextBox runat="server" text='<%#Eval("Active") %>' ID="txtActive" />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="PersonnelResourceType">
            <ItemTemplate>
                <asp:TextBox runat="server" text='<%#Eval("PersonnelResourceType") %>' ID="txtPersonnelResourceType" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
    <FooterStyle BackColor="#CCCC99" />
    <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
    <RowStyle BackColor="#F7F7DE" />
    <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
</asp:GridView>
<br />



C#


 protected void InsertButton_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            conn.Open();
            foreach (GridViewRow row in gvNEW.Rows)
            {
                gvNEW.Columns.RemoveAt(0);
                cmd.CommandText = "INSERT INTO StaffTracking (Project, Tower, Functional Area, ResourceName, CATWResourceName, Org, IndicateifBillingFP, IndicateifBillingTM, DefaultFTE, Active, PersonnelResourceType)" + " VALUES ( '" + ((TextBox)row.FindControl("txtProject")).Text + "', '" + ((TextBox)row.FindControl("txtTower")).Text + "', '" + ((TextBox)row.FindControl("txtFunctional Area")).Text + "', '" + ((TextBox)row.FindControl("txtResourceName")).Text + "', '" + ((TextBox)row.FindControl("txtCATWResourceName")).Text + "', '" + ((TextBox)row.FindControl("TxtOrg")).Text + "', '" + ((TextBox)row.FindControl("txtIndicateifBillingFP")).Text + "', '" +
                ((TextBox)row.FindControl("txtIndicateifBillingTM")).Text + "', '" + ((TextBox)row.FindControl("txtDefaultFTE")).Text + "', '" + ((TextBox)row.FindControl("txtActive")).Text + "', '" + ((TextBox)row.FindControl("txtPersonnelResourceType")).Text + "')";

                int numRegs = cmd.ExecuteNonQuery();
            }
            conn.Close();
            ResetInputForm();
        }  :sigh: 

AnswerRe: Not able to insert my data into sql db. Getting that annoying null error! Pin
Richard Deeming29-May-15 7:41
mveRichard Deeming29-May-15 7:41 
AnswerRe: Not able to insert my data into sql db. Getting that annoying null error! Pin
Sascha Lefèvre29-May-15 7:48
professionalSascha Lefèvre29-May-15 7:48 
GeneralRe: Not able to insert my data into sql db. Getting that annoying null error! Pin
Norris Chappell29-May-15 8:14
Norris Chappell29-May-15 8:14 
GeneralRe: Not able to insert my data into sql db. Getting that annoying null error! Pin
Sascha Lefèvre29-May-15 12:33
professionalSascha Lefèvre29-May-15 12:33 
GeneralRe: Not able to insert my data into sql db. Getting that annoying null error! Pin
Norris Chappell31-May-15 8:41
Norris Chappell31-May-15 8:41 
GeneralRe: Not able to insert my data into sql db. Getting that annoying null error! Pin
Sascha Lefèvre31-May-15 8:58
professionalSascha Lefèvre31-May-15 8:58 
QuestionLoad specific userControl from DLL Pin
Jassim Rahma29-May-15 5:29
Jassim Rahma29-May-15 5:29 
AnswerRe: Load specific userControl from DLL Pin
Bernhard Hiller29-May-15 5:55
Bernhard Hiller29-May-15 5:55 
Generalvideo streaming mvc3 c#,html5 and jquery Pin
saiguttina29-May-15 0:25
saiguttina29-May-15 0:25 
GeneralMessage Closed Pin
28-May-15 23:39
Member 1172789928-May-15 23:39 
AnswerRe: help with calculator program Pin
V.28-May-15 23:45
professionalV.28-May-15 23:45 
AnswerRe: help with calculator program Pin
OriginalGriff29-May-15 0:08
mveOriginalGriff29-May-15 0:08 
QuestionSharePoint Pin
Armugam Indrani28-May-15 22:41
professionalArmugam Indrani28-May-15 22:41 
AnswerRe: SharePoint Pin
Eddy Vluggen29-May-15 2:50
professionalEddy Vluggen29-May-15 2:50 
QuestionTCP Heartbeat background Thread Pin
MooKowMyke27-May-15 21:50
MooKowMyke27-May-15 21:50 
AnswerRe: TCP Heartbeat background Thread Pin
Eddy Vluggen29-May-15 2:57
professionalEddy Vluggen29-May-15 2:57 
GeneralRe: TCP Heartbeat background Thread Pin
MooKowMyke29-May-15 7:57
MooKowMyke29-May-15 7:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.