VB.NET -Web App: Problems Updating Datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tanya2001
    New Member
    • Nov 2007
    • 23

    #16
    Originally posted by Frinavale
    I'm glad to have helped.
    Please post a new thread in the .NET Forum about your other question :)
    (unless, of course, it's related to this one)

    -Frinny
    hi yes its related 2 this so m posting it here

    well d first 2 field in this r getting updated but then wen i have added 2 more fields in this its not updating...y is it so?
    m giving u d code below
    [code=vbnet]

    Dim Stocksent1 As TextBox = CType(e.Item.Fi ndControl("Text Box2"), TextBox)
    Dim Signed1 As TextBox = CType(e.Item.Fi ndControl("Sign edTextBox"), TextBox)
    Dim Takenby1 As TextBox = CType(e.Item.Fi ndControl("Text Box1"), TextBox)
    Dim Comments1 As TextBox = CType(e.Item.Fi ndControl("Text Box4"), TextBox)
    Dim Items1 As String = DataGrid1.DataK eys(e.Item.Item Index).ToString ()
    Dim myConnection As New SqlConnection(" Server=SERVER;u id=sa;pwd=;Data base=Central")
    myConnection.Op en()
    myCommand1 = New SqlCommand("Upd ate Table3 set Stocksent='" & Stocksent1.Text & "', Signedby='" & Signed1.Text & "',Takenby= '" & Takenby1.Text & "', Comments='" & Comments1.Text & "', Flag=0, Sentdate=getdat e() where Items='" & Items1 & "' ", myConnection)
    ra = myCommand1.Exec uteNonQuery()
    myConnection.Cl ose()
    Response.Write( "Records Updated")
    DataGrid1.EditI temIndex = -1
    DataGrid1.DataB ind()
    DataGrid1.Colum ns(8).Visible = False
    DataGrid1.Colum ns(9).Visible = False
    DataGrid1.Colum ns(10).Visible = False
    DataGrid1.Colum ns(11).Visible = False
    DataGrid1.Colum ns(12).Visible = False

    [/code]

    [code=html]
    <asp:datagrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 64px; POSITION: absolute; TOP: 296px"
    runat="server" Height="72px" BorderColor="#6 60033" BackColor="Whea t" ForeColor="DimG ray" Width="848px"
    DataKeyField="I tems" AutoGenerateCol umns="False">
    <HeaderStyle Font-Bold="True" ForeColor="Choc olate" BackColor="Ligh tGray"></HeaderStyle>
    <Columns>
    <asp:BoundColum n DataField="Logn umm" ReadOnly="True" HeaderText="Log numm"></asp:BoundColumn >
    <asp:BoundColum n DataField="Requ estdate" ReadOnly="True" HeaderText="Req uestdate"></asp:BoundColumn >
    <asp:BoundColum n DataField="Hosp ital" ReadOnly="True" HeaderText="Hos pital"></asp:BoundColumn >
    <asp:BoundColum n DataField="Item s" ReadOnly="True" HeaderText="Ite ms"></asp:BoundColumn >
    <asp:BoundColum n DataField="Curr entstock" ReadOnly="True" HeaderText="Cur rentstock"></asp:BoundColumn >
    <asp:BoundColum n DataField="Stoc krequest" ReadOnly="True" HeaderText="Sto ckrequest"></asp:BoundColumn >
    <asp:BoundColum n DataField="Prio rity" ReadOnly="True" HeaderText="Pri ority"></asp:BoundColumn >
    <asp:BoundColum n DataField="Comm ent" ReadOnly="True" HeaderText="Com ment"></asp:BoundColumn >
    <asp:TemplateCo lumn HeaderText="Sto cksent">
    <ItemTemplate >
    <asp:Label id=Label2 runat="server" Text='<%# DataBinder.Eval (Container.Data Item , "Stocksent" ) %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTempla te>
    <asp:TextBox id=TextBox2 runat="server" Text='<%# DataBinder.Eval (Container.Data Item , "Stocksent" ) %>'>
    </asp:TextBox>
    <asp:RequiredFi eldValidator id="RequiredFie ldValidator1" runat="server" ControlToValida te="TextBox2" ErrorMessage="E nter value"></asp:RequiredFie ldValidator>
    </EditItemTemplat e>
    </asp:TemplateCol umn>
    <asp:TemplateCo lumn HeaderText="Sig nedby">
    <ItemTemplate >
    <asp:Label id=Label1 runat="server" NAME="Label1" Text='<%# DataBinder.Eval (Container, "DataItem.Signe dby") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTempla te>
    <asp:TextBox id=SignedTextBo x runat="server" Text='<%# DataBinder.Eval (Container, "DataItem.Signe dby") %>'>
    </asp:TextBox>
    <asp:RequiredFi eldValidator id="RequiredFie ldValidator2" runat="server" Width="128px" ErrorMessage="E nter Value"
    ControlToValida te="SignedTextB ox"></asp:RequiredFie ldValidator>
    </EditItemTemplat e>
    </asp:TemplateCol umn>
    <asp:TemplateCo lumn HeaderText="Tak enby">
    <ItemTemplate >
    <asp:Label id="Label3" runat="server" Text='<%# DataBinder.Eval (Container, "DataItem.Taken by") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTempla te>
    <asp:TextBox id="TextBox1" runat="server" Text='<%# DataBinder.Eval (Container, "DataItem.Taken by") %>'>
    </asp:TextBox>
    <asp:RequiredFi eldValidator id="RequiredFie ldValidator3" runat="server" ErrorMessage="E nter Value" ControlToValida te="TextBox1"> </asp:RequiredFie ldValidator>
    </EditItemTemplat e>
    </asp:TemplateCol umn>
    <asp:TemplateCo lumn HeaderText="Com ments">
    <ItemTemplate >
    <asp:Label id="Label4" runat="server" Text='<%# DataBinder.Eval (Container, "DataItem.Comme nts") %>'>
    </asp:Label>
    </ItemTemplate>
    <EditItemTempla te>
    <asp:TextBox id="TextBox3" runat="server" Text='<%# DataBinder.Eval (Container, "DataItem.Comme nts") %>'>
    </asp:TextBox>
    </EditItemTemplat e>
    </asp:TemplateCol umn>
    <asp:TemplateCo lumn HeaderText="Edi t">
    <ItemTemplate >
    <asp:LinkButt on runat="server" CausesValidatio n="false" CommandName="Ed it" Text="Edit" ID="Linkbutton1 "></asp:LinkButton>
    </ItemTemplate>
    <EditItemTempla te>
    <asp:LinkButt on runat="server" CommandName="Up date" Text="Update" ID="Linkbutton2 "></asp:LinkButton>
    <asp:LinkButt on runat="server" CausesValidatio n="false" CommandName="Ca ncel" Text="Cancel" ID="Linkbutton3 "></asp:LinkButton>
    </EditItemTemplat e>
    </asp:TemplateCol umn>
    </Columns>
    </asp:datagrid>
    [/code]

    ERROR:

    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullRefe renceException: Object reference not set to an instance of an object.


    Line 66: myCommand1 = New SqlCommand("Upd ate Table3 set Stocksent='" & Stocksent1.Text & "', Signedby='" & Signed1.Text & "',Takenby= '" & Takenby1.Text & "', Comments='" & Comments1.Text & "', Flag=0, Sentdate=getdat e() where Items='" & Items1 & "' ", myConnection)

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #17
      Originally posted by tanya2001
      hi yes its related 2 this so m posting it here

      well d first 2 field in this r getting updated but then wen i have added 2 more fields in this its not updating...y is it so?
      m giving u d code below...
      ERROR:

      Object reference not set to an instance of an object.
      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

      Exception Details: System.NullRefe renceException: Object reference not set to an instance of an object.


      Line 66: myCommand1 = New SqlCommand("Upd ate Table3 set Stocksent='" & Stocksent1.Text & "', Signedby='" & Signed1.Text & "',Takenby= '" & Takenby1.Text & "', Comments='" & Comments1.Text & "', Flag=0, Sentdate=getdat e() where Items='" & Items1 & "' ", myConnection)
      This type of error means that you are trying to use a variable before it has been initialized. For each object you should be using "new". Since you are grabbing these objects from the DataGrid, I recommend checking to see if any of them are are nothing....

      Eg
      [code=vbnet]
      If Stocksent1 Is Nothing Then
      'if you try to use Stocksent1 when it is nothing you will get this error.
      'Do something here to avoid your exception
      End If[/code]

      Also, just a side note here but it's important, you shouldn't be using input directly from the user for creating your database query. This is dangerous and could result in your site being hacked.

      Please see the .NET article on how to use a database in your program for an example on how to use these parameters correctly. This may also help you to figure out which variable is actually causing your error as well.

      -Frinny

      Comment

      • tanya2001
        New Member
        • Nov 2007
        • 23

        #18
        Originally posted by Frinavale
        This type of error means that you are trying to use a variable before it has been initialized. For each object you should be using "new". Since you are grabbing these objects from the DataGrid, I recommend checking to see if any of them are are nothing....

        Eg
        [code=vbnet]
        If Stocksent1 Is Nothing Then
        'if you try to use Stocksent1 when it is nothing you will get this error.
        'Do something here to avoid your exception
        End If[/code]

        Also, just a side note here but it's important, you shouldn't be using input directly from the user for creating your database query. This is dangerous and could result in your site being hacked.

        Please see the .NET article on how to use a database in your program for an example on how to use these parameters correctly. This may also help you to figure out which variable is actually causing your error as well.

        -Frinny

        alright..but wen i was using the 1st 2 fields it worked wen ma dding these 2 new fields in d same way its not working..though wen i comment them n work d first 2 still work..though all of them have been initialized d same way....

        Comment

        • tanya2001
          New Member
          • Nov 2007
          • 23

          #19
          Originally posted by tanya2001
          alright..but wen i was using the 1st 2 fields it worked wen ma dding these 2 new fields in d same way its not working..though wen i comment them n work d first 2 still work..though all of them have been initialized d same way....
          i got the answer i was just doin a simple mistake by giving a wrong textbox name....thanx 4 ur help anywayz.. posting a new query on crystal reports...help me out if u can in it...tc

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #20
            Originally posted by tanya2001
            i got the answer i was just doin a simple mistake by giving a wrong textbox name....thanx 4 ur help anywayz.. posting a new query on crystal reports...help me out if u can in it...tc
            Good work!
            Feel free to ask for help any time :)

            Comment

            • tanya2001
              New Member
              • Nov 2007
              • 23

              #21
              Originally posted by Frinavale
              Good work!
              Feel free to ask for help any time :)

              hi there i have a new query...jts go 2 this link n help me out plzzz

              http://www.thescripts. com/forum/showthread.php? p=2943265#post2 943265

              Comment

              • Frinavale
                Recognized Expert Expert
                • Oct 2006
                • 9749

                #22
                Originally posted by tanya2001
                hi there i have a new query...jts go 2 this link n help me out plzzz

                http://www.thescripts. com/forum/showthread.php? p=2943265#post2 943265
                Sorry Tanya,
                I have never used crystal reports in my life...can't help you on that one.

                Comment

                • tanya2001
                  New Member
                  • Nov 2007
                  • 23

                  #23
                  Originally posted by Frinavale
                  Sorry Tanya,
                  I have never used crystal reports in my life...can't help you on that one.

                  hi
                  can u tell me if i can just add the values from a column based on 2 conditions and display d values in a different table?

                  Comment

                  • Frinavale
                    Recognized Expert Expert
                    • Oct 2006
                    • 9749

                    #24
                    Originally posted by tanya2001
                    hi
                    can u tell me if i can just add the values from a column based on 2 conditions and display d values in a different table?
                    What kind of table are you talking about?

                    Comment

                    Working...