how to create unique identity based on comboboxes text selection in visual basic 2010 form
-
11. června 2012 19:29
hello world,
i have a form which is having combo boxes which is connected with ms access database.
i am using following code to fill combo boxes:
Private Sub loadcourse()
Dim OleDBC As New OleDbCommand
Dim OleDBDR As OleDbDataReader
With OleDBC
.Connection = conn
.CommandText = "SELECT coursename FROM tblcourse"
End With
OleDBDR = OleDBC.ExecuteReader
cmbcourse.Items.Clear()
If OleDBDR.HasRows Then
While OleDBDR.Read
cmbcourse.Items.Add(OleDBDR.Item(0))
End While
End If
End Sub
Private Sub loadcourseyear()
Dim OleDBC As New OleDbCommand
Dim OleDBDR As OleDbDataReader
With OleDBC
.Connection = conn
.CommandText = "SELECT courseyear FROM tblcourseyear"
End With
OleDBDR = OleDBC.ExecuteReader
cmbcourseyear.Items.Clear()
If OleDBDR.HasRows Then
While OleDBDR.Read
cmbcourseyear.Items.Add(OleDBDR.Item(0))
End While
End If
End Subnow i am filling my textbox1 with these code:
Private Sub cmbcourse_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbcourse.SelectedIndexChanged
If cmbcourse.Text = "B.A." Then
txtrollnumber.Text = "201301"
End If
If cmbcourse.Text = "M.A." Then
txtrollnumber.Text = "201302"
End If
If cmbcourse.Text = "B.Sc." Then
txtrollnumber.Text = "201303"
End If
End Sub
Private Sub cmbcourseyear_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbcourseyear.SelectedIndexChanged
If cmbcourseyear.Text = "I" Then
txtrollnumber.Text = txtrollnumber.Text + "01"
End If
If cmbcourseyear.Text = "II" Then
txtrollnumber.Text = txtrollnumber.Text + "02"
End If
If cmbcourseyear.Text = "III" Then
txtrollnumber.Text = txtrollnumber.Text + "03"
End If
End Subas you can see i just want to create a unique ID with course selection and courseyear selection i.e.
if i select "B.A." from cmbcourse and "II" form cmbcourseyear the textbox fills with number - 20130102 this is because i want to save data year wise.
now i want to add 0001,0002,0003 and so.no........ in front of the number in the textbox in increment order. so that whenever the comboboxes selected the next number must find from the database and in front of textbox number.
the form have two buttons
1.SAVE
2.ADD
when SAVE click the data from form must save in database table.
is it possible when i click ADD button the textbox should clear and fill with selection of cmbcourse and after that selection of cmbcourseyear and then find the max number from the access database table and fill the total rollnumber.
sorry for my pure explanation because i am new in vb.net and trying to do some thing for our institution.
i am using this process because i want to save record in YEAR-WISE.
is it any way to make program more useful
please solve my problem with code help.
thanks in advanced.
- Změněný typ sanny007 25. června 2012 17:15
Všechny reakce
-
13. června 2012 6:09
Hi,
you need to learn more about database and SQL query.
Instead of asking code, please google OR learn more about basic knowledge. If the following code is WRITTEN by you, I'm sure there will be no issue about your question.
Writing SQL Queries: Let's Start with the Basics:http://msdn.microsoft.com/en-us/library/bb264565(v=sql.90).aspx
ADO.NET Overview:http://msdn.microsoft.com/en-us/library/h43ks021(v=VS.100).aspx
No code, No fact.
-
13. června 2012 18:01
hi,
thanks for reply
as u can see the second part of code is written by me.
but i don't know how to proceed further.
please help me.
-
30. června 2012 23:43
hi,
for adding the Text to the TextBox you can use Append method of TextBox as....
TextBox.Append()
For Unique Id you can check database to give the next unique id to that row...and increment it by 1 for next id...
- Navržen jako odpověď VarunShrivastava 25. září 2012 18:10