| | |
How do I store Unique Values to More than One Same Names in Database using VB.NET
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2006
Posts: 13
Reputation:
Solved Threads: 0
How do I store Unique Values to More than One Same Names in Database using VB.NET
0
#1 Aug 24th, 2006
Hi,
My problem is
Am using SQL SERVER as database with VB.NET as Front End.
I do have a database Known as Trackers with a Table known as Emp
In Emp,I have the fields as Name,Surname,Emp_ID,Address.
Here I have made the Emp_ID in the database..its Identity to "Yes"..so that the database automatically generates unique number.
I have a combobox named Cmb_EmpName and it contains the Name of the Employees(ie both the Name and Surname together)....suppose in the database i have two same names...ie eg: Tom Alex and Emp_ID=12, and another row Tom Alex and Emp_ID=13 (Here Emp_ID is being automatically generated...)
so in the Combo box named Cmb_EmpName,it will populate two names...ie Tom Alex
Tom Alex
When I click on Tom Alex,ie the sescond one,it takes only the first.
In Visual Basic, I know how to do.
Code in Visual Basic
----------------------
In the FormLoad
Dim cnn As New ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim i As Integer
Set cnn = New ADODB.Connection
cnn.Open "DSN=Telemanagement;uid=sa;pwd=sa"
Set rs1 = New ADODB.Recordset
rs1.Open "SELECT Emp_ID,Emp_Name+' '+Emp_Surname as Name from Employees", cnn, adOpenStatic, adLockReadOnly
Do While Not rs1.EOF
Cmb_EmpName.AddItem rs1.Fields("Name").Value
Cmb_EmpName.ItemData(Cmb_EmpName.NewIndex) = rs1.Fields("Emp_ID")// Here is where we are storing every value of Emp_ID to the corresponding Name
rs1.MoveNext
Loop
so that if there are more than one same names,i can click any names because the Emp_ID is unique for each rows.
ie Tom Alex With Emp_ID 12
or
Tom Alex With Emp_ID 13
Like Wise in VB.NET..is there any code for this line
ie Cmb_EmpName.ItemData(Cmb_EmpName.NewIndex)=rs1.Fields("Emp_ID")
because in VB.NET,I couldn't find a property known as ItemData or New Index....In VB.NET there is only Items,Selected Index,Selected Items,Select..
Is there any similiar words like ItemData,New Index of Visual Basic in that of the VB.NET
So can anyone help me out of this problem....
I know am putting too much trouble on you guys..sorry but thanks lot
Cheers
B.H
My problem is
Am using SQL SERVER as database with VB.NET as Front End.
I do have a database Known as Trackers with a Table known as Emp
In Emp,I have the fields as Name,Surname,Emp_ID,Address.
Here I have made the Emp_ID in the database..its Identity to "Yes"..so that the database automatically generates unique number.
I have a combobox named Cmb_EmpName and it contains the Name of the Employees(ie both the Name and Surname together)....suppose in the database i have two same names...ie eg: Tom Alex and Emp_ID=12, and another row Tom Alex and Emp_ID=13 (Here Emp_ID is being automatically generated...)
so in the Combo box named Cmb_EmpName,it will populate two names...ie Tom Alex
Tom Alex
When I click on Tom Alex,ie the sescond one,it takes only the first.
In Visual Basic, I know how to do.
Code in Visual Basic
----------------------
In the FormLoad
Dim cnn As New ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim i As Integer
Set cnn = New ADODB.Connection
cnn.Open "DSN=Telemanagement;uid=sa;pwd=sa"
Set rs1 = New ADODB.Recordset
rs1.Open "SELECT Emp_ID,Emp_Name+' '+Emp_Surname as Name from Employees", cnn, adOpenStatic, adLockReadOnly
Do While Not rs1.EOF
Cmb_EmpName.AddItem rs1.Fields("Name").Value
Cmb_EmpName.ItemData(Cmb_EmpName.NewIndex) = rs1.Fields("Emp_ID")// Here is where we are storing every value of Emp_ID to the corresponding Name
rs1.MoveNext
Loop
so that if there are more than one same names,i can click any names because the Emp_ID is unique for each rows.
ie Tom Alex With Emp_ID 12
or
Tom Alex With Emp_ID 13
Like Wise in VB.NET..is there any code for this line
ie Cmb_EmpName.ItemData(Cmb_EmpName.NewIndex)=rs1.Fields("Emp_ID")
because in VB.NET,I couldn't find a property known as ItemData or New Index....In VB.NET there is only Items,Selected Index,Selected Items,Select..
Is there any similiar words like ItemData,New Index of Visual Basic in that of the VB.NET
So can anyone help me out of this problem....
I know am putting too much trouble on you guys..sorry but thanks lot
Cheers
B.H
•
•
Join Date: Aug 2006
Posts: 5
Reputation:
Solved Threads: 0
Re: How do I store Unique Values to More than One Same Names in Database using VB.NET
0
#2 Sep 7th, 2006
chek for lastindex...
or else use the following :
dim i
i=combobox1. Items.count
the count has the highest index + 1 of your combo's items....
further help, mail at pwy_20002001@yahoo.co.in with full code.
or else use the following :
dim i
i=combobox1. Items.count
the count has the highest index + 1 of your combo's items....
further help, mail at pwy_20002001@yahoo.co.in with full code.
![]() |
Similar Threads
- SQL Injection Attack (Database Design)
- Parameter error for executeNonQuery() (VB.NET)
- Basic SQL made Hard (MS SQL)
- Please Help Me, I Am to Be Fired! (ASP.NET)
- How to auto increment? (ASP.NET)
- Maps in VC++ 6.0 (C++)
- Problem in getting values of a text area by row and column wise (ASP)
Other Threads in the VB.NET Forum
- Previous Thread: Help me
- Next Thread: ..joining 2 tables?=A tuf one....can U crack this ?
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account arithmetic array arrays basic bing button buttons c# center check checkbox code convert crystalreport data database datagrid datagridview date dissertation dissertations dropdownlist excel fade file-dialog filter ftp generatetags google gridview hardcopy images inline input insert intel internet listview mobile monitor ms net networking objects output panel passingparameters picturebox picturebox1 port position print printing problem project read remove save searchbox searchvb.net select serial server shutdown soap sorting survey table tcp temperature text textbox timer timespan toolbox trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web winforms wpf year





