Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Protected Sub btnFirst_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnFirst.Click
      Dim i As Long = 0

      Dim str1 As String = "SELECT Min(IT_CODE_ACT) FROM PS_EXT_MAST "

      conn.Open()
      Dim cmd1 As SqlCommand = New SqlCommand(str1, conn)
      Dim dr As SqlDataReader = cmd1.ExecuteReader()

      dr.Read()
      If dr.HasRows Then
          txtItemCode.Text = dr(0).ToString()
          i = Convert.ToInt32(txtItemCode.Text)
      End If
      conn.Close()

      Dim str2 As String = "select IT_DESC from PS_EXT_MAST where IT_CODE_ACT= " + i
      conn.Open()
      Dim cmd2 As SqlCommand = New SqlCommand(str2, conn)
      Dim dr2 As SqlDataReader = cmd2.ExecuteReader()
      dr2.Read()

      If dr2.HasRows Then
          txtItemDesc.Text = dr2(0).ToString()

      End If
      conn.Close()

      Response.Write("<Script>alert(' First record found....')</Script>")
  End Sub

  Protected Sub btnLast_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnLast.Click
      Dim i As Long = 0

      Dim str1 As String = "SELECT Max(IT_CODE_ACT) FROM PS_EXT_MAST"
      conn.Open()
      Dim cmd1 As SqlCommand = New SqlCommand(str1, conn)
      Dim dr As SqlDataReader = cmd1.ExecuteReader()

      dr.Read()
      If dr.HasRows Then
          txtItemCode.Text = dr(0).ToString()
          i = Convert.ToInt32(txtItemCode.Text)
      End If
      conn.Close()

      Dim str2 As String = "select IT_DESC from PS_EXT_MAST where IT_CODE_ACT=" + i
      conn.Open()
      Dim cmd2 As SqlCommand = New SqlCommand(str2, conn)
      Dim dr2 As SqlDataReader = cmd2.ExecuteReader()
      dr2.Read()
      If dr2.HasRows Then
          txtItemDesc.Text = dr2(0).ToString()
      End If
      conn.Close()

      Response.Write("<Script>alert(' Last record found....')</Script>")
  End Sub



***I want to fetch alphanumeric max/min value from sqlserver
error is occured, what will be my query?
Posted
Comments
Sandeep Mewara 6-Jul-12 9:44am    
How can an alphanumeric can have a max or min?

You would first need to define what a min/max alphanumeric value is because for numbers this is clear but for alphanumeric values it isn't. If you mean min/max as in A-z, you could sort on that specific field and take the first and last record in the set.

Sidenote: The way you code using sql like this is a security hazard waiting to happen. At least have a look at sql parameters.

Good luck!
 
Share this answer
 
For this you can use order by Aggregate function with Ascending and descending like
select name from table1 order by(name) decs / Asc.
i hope this give some help you
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900