10 Replies - 841 Views - Last Post: 04 October 2012 - 12:51 PM

#1 xhanemila4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 29-September 12

Max() function stops at 10

Posted 04 October 2012 - 06:24 AM

Hi I'm using max() function to set auto_increment in database but the problem is it stops adding when it reaches 10. Upon it reaches 10 all the columns after that will be 10 , i have this code

   connectToDatabase()
        openConnection()
        incrementmoni()
        Try
            Dim i As Integer
            i = command.ExecuteScalar()
            lbllog.Text = i.ToString + 1

        Catch ex As Exception

        End Try
        closeConnection() 


Sub incrementmoni()
        command = New SqlCommand("select max(Monitor_Number) from tbl_monitor", connection)
        adapter.SelectCommand = command
    End Sub




Is This A Good Question/Topic? 0
  • +

Replies To: Max() function stops at 10

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,611
  • Joined: 08-June 10

Re: Max() function stops at 10

Posted 04 October 2012 - 07:40 AM

your code only fetches the number, but does not set it. besides that, if you have an autoincremented column, why set the number manually?
Was This Post Helpful? 0
  • +
  • -

#3 xhanemila4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 29-September 12

Re: Max() function stops at 10

Posted 04 October 2012 - 09:36 AM

Hi Dormilich, i can increment it from 1 upto 10 but after that next number will be 10, and i cant set the column in auto increment since im using the my sql built in withing the visual studio 2008. That's why i use this method. Just to add up my question how can i determine if the column is null? so i make the label as 1 to start.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,611
  • Joined: 08-June 10

Re: Max() function stops at 10

Posted 04 October 2012 - 10:39 AM

could you post your table setup?
Was This Post Helpful? 0
  • +
  • -

#5 xhanemila4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 29-September 12

Re: Max() function stops at 10

Posted 04 October 2012 - 11:51 AM

what you mean by setup? the table definition? sorry I don't have the laptop with the program. The columns looks like this Auto_ID, Student_Number , Fname , Lname , Mname . But to be honest i really don't want to use the max function if i can use the auto increment method in database.
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,611
  • Joined: 08-June 10

Re: Max() function stops at 10

Posted 04 October 2012 - 12:31 PM

yes, the table definition.

but I donít understand, how a getter function like MAX() is supposed to set a field value.
Was This Post Helpful? 0
  • +
  • -

#7 xhanemila4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 29-September 12

Re: Max() function stops at 10

Posted 04 October 2012 - 12:35 PM

I just use max to get the highest value in Auto_ID column then put it in a label as integer then add +1 yea it can cause auto increment but when it reaches 10 it stop i think I'm missing something like it can only read 1 digit number
Was This Post Helpful? 0
  • +
  • -

#8 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,611
  • Joined: 08-June 10

Re: Max() function stops at 10

Posted 04 October 2012 - 12:36 PM

maybe the data type of the column is wrong?
Was This Post Helpful? 1
  • +
  • -

#9 xhanemila4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 29-September 12

Re: Max() function stops at 10

Posted 04 October 2012 - 12:44 PM

Sure ill check it then post what i got. Btw can i ask another question? Example I have a table like this

Auto_ID Name Status
1 apple In
2 apple Out
4 apple In
5 Mango In

i want to select all name with "In" Status i tried to use select name from table where value = in
but returns 2 apple and 1 mango. But i just want to get the latest In of apple and count it as 1
so the it will give me apple and Mango only
Was This Post Helpful? 0
  • +
  • -

#10 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3402
  • View blog
  • Posts: 9,611
  • Joined: 08-June 10

Re: Max() function stops at 10

Posted 04 October 2012 - 12:46 PM

if you only want the name, use SELECT DISTINCT.
Was This Post Helpful? 0
  • +
  • -

#11 xhanemila4  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 29-September 12

Re: Max() function stops at 10

Posted 04 October 2012 - 12:51 PM

I need all the columns because i will display it in a datagridview. But no worries i can do the display only the selection of data from database
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1