473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

displaying value twice

Hi Team,

below coding is working fine. it was displaying the value in the list box once i press the button1. But when i click the button1 once more the result was getting twice. i.e., previous value is displayed plus same value was repeated twice. overall three times. please help me in this regard.


Expand|Select|Wrap|Line Numbers
  1.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2.         Try
  3.  
  4.             con.Open()
  5.             MsgBox("con opened..")
  6.             cmd.CommandType = CommandType.Text
  7.             cmd.CommandText = "select * from student"
  8.             da = New SqlDataAdapter(cmd.CommandText, con)
  9.             da.Fill(ds)
  10.  
  11.             Dim i, maxcount As Integer
  12.             maxcount = ds.Tables(0).Rows.Count
  13.  
  14.             Dim a(maxcount - 1) As String
  15.             For i = 0 To maxcount - 1
  16.                 a(i) = ds.Tables(0).Rows(i).Item(1)
  17.             Next
  18.             For i = 0 To maxcount - 1
  19.                 ListBox1.Items.Add(a(i))
  20.             Next
  21.         Catch ex As Exception
  22.             MsgBox(ex.Message.ToString)
  23.         End Try
  24.         con.Close()
  25.         MsgBox("con closed..")
  26.     End Sub
May 4 '10 #1
2 1040
Monomachus
127 Expert 100+
@krisssgopi
Hi, please add tags to your question.
Now on the topic I can see why these values could be doubled.

Because you don't clear you old values from your listbox before inserting the new ones:

Expand|Select|Wrap|Line Numbers
  1. Listbox1.Items.Clear();
  2.  
But I don't know how to explain that it was repeated two times (overall three).

Please try to clear the items and see what happens next.

P.S. Please use code button or tags to insert the code. Thanks in advance

May 4 '10 #2
@Monomachus
Hi Mono really thanks for your reply... one more think ow to develop my developing skills please advise me in this regard. thanks in advance..
May 5 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: pmud | last post by:
Hi, I have 4 columns in my sql database table. I added a data adapter , data set & a data grid to view this information. But the data grid is displaying those 4 columns TWICE , i.e in the data...
6
by: Matt K. | last post by:
Hi there, I have a form in an Access project that contains a subform which displays the results of a query of the style "select * from where = #a certain date#". In the main part of the form...
8
by: Vince Varallo | last post by:
Hello All, I would like to display all logged on users on a web page. I store each user's name in a session varible, but I don't seem to be able to loop through a sessions collection to view...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
4
by: Jack | last post by:
Hi, I have the following Access DDL statment from which I generated a access table: CREATE TABLE TEST1 (ID COUNTER, NAME TEXT(50), STORAGESPACEASSIGNED TEXT(50) )
2
by: Severus Snape | last post by:
I can display and hide 1 object at a time, but haven't seen it done on multiple objects simultaneously. I have four (or more) tables on a page that start off hidden, and I want to toggle their...
0
by: arunpulikkan | last post by:
hi,guys im new to asp.in my option list one value is displaying twice.following is the code if not rs1.eof then thispagesForm = rs1(0) sql2 = "select formname, local_url from...
16
by: Akhenaten | last post by:
I must be missing something rather obvious. I have the following snippet of code that echo's my result twice when it should be echoing just once (only one element in the array). What am I...
1
by: johnVarma | last post by:
Hi All, Iam facing a problem with bar chart using coldFusion. if there is only one <cfchartseries> tag then the seriesLabel attribute is not displaying instead of that the items of the...
7
by: Ned White | last post by:
Is it possible to insert HTML codes to a textbox control ? I am reading HTML formated string from sql server but if i assign this value to Text property of TextBox, the format tags of HTML seems...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.