Problem with String Data Type

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MrMike

    #1

    Problem with String Data Type

    I'm working with a DataGrid UpdateCommand event and running into a problem.
    The second column of the dg is the PK named "FlitchNum" . The datatype of
    this PK is varchar(string) . In the event I need to obtain the value of this
    field in order to pass it into a SQL command. However, when I use the
    syntax: "Dim FlitchID As String = e.Item.Cells(1) .Text" nothing populates the
    FlitchID variable. Below is the code. How do I simply select the textual
    value of the contents of column 3? Thanks
    -------------------------------------------------------------------------------------
    Private Sub DataGrid1_Updat eCommand(ByVal source As Object, _
    ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) _
    Handles DataGrid1.Updat eCommand
    Dim DDL As DropDownList = _
    CType(e.Item.Ce lls(2).Controls (1), DropDownList)
    Dim NewShip As Integer = DDL.SelectedVal ue
    Dim FlitchID As String = e.Item.Cells(1) .Text
    Response.Write( FlitchID)
    Dim SQL As String = _
    "UPDATE tblLogs SET SpecieID=@Speci e WHERE FlitchID=@ID"
    Dim Conn As SqlConnection = New SqlConnection(" integrated
    security=SSPI;d ata source=sjserver 1;persist security info=False;init ial
    catalog=sjerp")
    Dim Cmd As New SqlCommand(SQL, Conn)
    Cmd.Parameters. Add(New SqlParameter("@ Specie", NewShip))
    Cmd.Parameters. Add(New SqlParameter("@ ID", FlitchID))
    Conn.Open()
    Cmd.ExecuteNonQ uery()
    Conn.Close()
    DataGrid1.EditI temIndex = -1
    DataGrid1.DataB ind(
    -------------------------------------------------------------------------------------
  • Jon Skeet [C# MVP]

    #2
    Re: Problem with String Data Type

    MrMike <MrMike@discuss ions.microsoft. com> wrote:[color=blue]
    > I'm working with a DataGrid UpdateCommand event and running into a problem.
    > The second column of the dg is the PK named "FlitchNum" . The datatype of
    > this PK is varchar(string) . In the event I need to obtain the value of this
    > field in order to pass it into a SQL command. However, when I use the
    > syntax: "Dim FlitchID As String = e.Item.Cells(1) .Text" nothing populates the
    > FlitchID variable.[/color]

    That sounds very strange. Does e.Item.Cells(1) .Text definitely have a
    non-null value? How are you determining that FlitchID has not been set?

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • MrMike

      #3
      Re: Problem with String Data Type

      Thanks for your reply. FlitchNum is the PK, so it cannot contain a null
      value. This column is a template column, generated using the code below.
      Should this make any difference? Thanks.

      <asp:TemplateCo lumn HeaderText="Fli tch#">
      <ItemTemplate >
      <asp:HyperLin k runat="server" Text='<%# DataBinder.Eval (Container,
      "DataItem.Flitc hNum") %> ' NavigateURL='<% # "Logs_Detail.as px?id=" &
      DataBinder.Eval (Container, "DataItem.Flitc hNum") %>' Target="_self"
      Name="HyperLink 1">
      </asp:HyperLink>
      </ItemTemplate>
      </asp:TemplateCol umn>




      "Jon Skeet [C# MVP]" wrote:
      [color=blue]
      > MrMike <MrMike@discuss ions.microsoft. com> wrote:[color=green]
      > > I'm working with a DataGrid UpdateCommand event and running into a problem.
      > > The second column of the dg is the PK named "FlitchNum" . The datatype of
      > > this PK is varchar(string) . In the event I need to obtain the value of this
      > > field in order to pass it into a SQL command. However, when I use the
      > > syntax: "Dim FlitchID As String = e.Item.Cells(1) .Text" nothing populates the
      > > FlitchID variable.[/color]
      >
      > That sounds very strange. Does e.Item.Cells(1) .Text definitely have a
      > non-null value? How are you determining that FlitchID has not been set?
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too
      >[/color]

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Problem with String Data Type

        MrMike <MrMike@discuss ions.microsoft. com> wrote:[color=blue]
        > Thanks for your reply. FlitchNum is the PK, so it cannot contain a null
        > value.[/color]

        That may be true in theory, but is it true in your particular case? It
        seems more likely that that would be wrong than that variable
        assignment is broken.
        [color=blue]
        > This column is a template column, generated using the code below.
        > Should this make any difference? Thanks.[/color]

        Don't know, I'm afraid...

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • Øystein Sundsbø - Bekk Consulting AS

          #5
          Re: Problem with String Data Type

          Your FlitchNum is stored in the HyperLink's Text attribute, not in the Text
          attribute of the DataGrid's Cell.

          You need to give your HyperLink an ID and use e.FindControl(" <ID>") to get
          an instance of your control and cast it to the type of HyperLink. Then you
          can extract the FlitchNum from the control's Text property.


          "Jon Skeet [C# MVP]" wrote:
          [color=blue]
          > MrMike <MrMike@discuss ions.microsoft. com> wrote:[color=green]
          > > Thanks for your reply. FlitchNum is the PK, so it cannot contain a null
          > > value.[/color]
          >
          > That may be true in theory, but is it true in your particular case? It
          > seems more likely that that would be wrong than that variable
          > assignment is broken.
          >[color=green]
          > > This column is a template column, generated using the code below.
          > > Should this make any difference? Thanks.[/color]
          >
          > Don't know, I'm afraid...
          >
          > --
          > Jon Skeet - <skeet@pobox.co m>
          > http://www.pobox.com/~skeet
          > If replying to the group, please do not mail me too
          >[/color]

          Comment

          Working...