Click here to Skip to main content
16,004,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to generate latest asset no, when you select USB pendrive from dropdownlist, it will autogenerate asset no into textbox before we save to database.

Example, if you choose USB pendrive -- asset no will start USB0001DD, number is auto increment.
USB HardDisk -- USB0502HDD
MP3 Player -- MP30027

Please advice. Really need help


Thanks in advance.
Posted
Comments
Harshil_Raval 11-Sep-13 3:26am    
Can you give more detail about your db structure? Because every time on selected index change event of dropdown, you must call to db for last input of your desire string. and according to that you need to add +1 counter to it and show in textbox.
Reena Aleesya 12-Sep-13 3:47am    
I got error said that "Input string was not in a correct format."

My database - portableid(int), portablename(varchar), assetno(varchar)

Below is my coding:

Dim temp As String
Dim i As String

Dim con1 As New SqlConnection("Server=10.1.2.215; Data Source=KILIMANJARO\BOSS_NET_DB; Initial Catalog=CMOS; User Id=sa1; password= sa1")
con1.Open()
Dim cmd2 As New SqlCommand("Select Max(assetno) as assetno from PortableStorage", con1)
cmd2.CommandType = CommandType.Text
Dim r As SqlDataReader = cmd2.ExecuteReader()
r.Read()

If r("assetno").ToString() <> "" Then

'temp = Integer.Parse(r("empid").ToString()) + 1
i = Integer.Parse(r("assetno").ToString()) + 1
temp = Convert.ToString(i)
Else

temp = 1
End If

TextBox4.Text = DropDownList1.SelectedValue + temp.ToString()

r.Close()
con1.Close()
Harshil_Raval 13-Sep-13 2:41am    
Are you sure, assetno field value does not contain any character? If it contains character then at i = Integer.Parse(r("assetno").ToString()) + 1, it will give you an error. I am not familiar with vb code. but i found code to fetch number from string. Dim number = r("assetno").ToString().Split(" "c).Where(Function(f) IsNumeric(f)).FirstOrDefault, Then use this Dim number in your logic.
VishwaKL 11-Sep-13 3:32am    
Your problem has a solution see you choosing USB/MP3 rt, that time you check the type which is selected by user and make the String USB/MP3 and while inserting to data base check that string USB/MP3 make a increment of the value by comparing data base value
Reena Aleesya 12-Sep-13 3:50am    
can you help me the example code, when user selected MP3 the asset no will be start from MP3 follow by 4 digit running number. My head already freeze!!!

Thanks in advance.

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