.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> VB.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Generate sequence numbers in textbox using vb.net

Posted By: srini     Posted Date: September 28, 2010    Points:2   Category :VB.Net
I am working on student application form in vb.net. I designed a form with fields like firstname,Middlename,Lastname,age,sex,DOB,Education.Height and Weight. Back end as SQL Server 2005. I just want to generate sequence numbers in textbox using vb.net. While loading the form,i should generate number as '1' and second time,if the form gets loading it shows '2' and goes on... Please Help me...

Responses
Author: Ramesh durai             
Posted Date: September 29, 2010     Points: 5   

hi,

For what purpose You generate sequence no.whether record counting depending on database or just display during page refresh?

Ramesh durai
Author: srini             
Posted Date: September 29, 2010     Points: 5   

Just need to display the numbers in textbox like 1,2,3,4 and so on......,while loading the form everytime..(first time 1,second time 2....) If i enter all the details like firstname,Middlename,Lastname,age,sex,DOB,Education.Height and Weight,once i click "Save",it should store on Database including Serial no(Generated on textbox).

Srini
Author: Ramesh durai             
Posted Date: September 29, 2010     Points: 5   

hi,

during page load. retrive count of data from ur table

ex:select count(*) as max from <tbl_name>

then use
textbox1.text=max+1;

that's all

depending on data in ur table textbox value gets increment.


Ramesh durai
Author: srini             
Posted Date: September 29, 2010     Points: 5   

I will send you the full coding through attachment. You just tell where to put this line sir,
Please help me.

Download Attachment

Srini
Author: srini             
Posted Date: September 29, 2010     Points: 5   

Please help me soon Ramesh sir

Srini
Author: Ramesh durai             
Posted Date: September 29, 2010     Points: 5   



i cant download that from link ma.

Ramesh durai
Author: srini             
Posted Date: September 29, 2010     Points: 5   

i will send again sir.

Download Attachment

Srini
Author: srini             
Posted Date: September 29, 2010     Points: 5   

Now can you able to download sir?

Srini
Author: Ramesh durai             
Posted Date: September 29, 2010     Points: 5   

Now too.

just copy and paste that page coding here.

Ramesh durai
Author: srini             
Posted Date: September 29, 2010     Points: 5   

Imports System.Data.SqlClient
Public Class Student_Form_Detail
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim da As SqlDataAdapter
Dim ds As DataSet

Private Sub Student_Form_Detail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


Me.DevelopTableAdapter.Fill(Me.DevDataSet5.develop)
conn = New SqlConnection("Data Source=.;Initial Catalog=Dev;Integrated Security=True")
End Sub

Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOk.Click

cmd = New SqlCommand("insert into develop values('" + txtFirst.Text + "','" + txtMiddle.Text + "','" + txtLast.Text + "'," + txtAge.Text + ",'" + txtSex.Text + "'," + txtDob.Text + ",'" + txtEdu.Text + "'," + txtHeight.Text + "," + txtWeight.Text + ")", conn)
da = New SqlDataAdapter(cmd)
ds = New DataSet()
conn.Open()
cmd.ExecuteNonQuery()
da.Fill(ds)
conn.Close()
txtFirst.Text = ""
txtMiddle.Text = ""
txtLast.Text = ""
txtAge.Text = ""
txtSex.Text = ""
txtDob.Text = " "
txtEdu.Text = ""
txtHeight.Text = ""
txtWeight.Text = ""
End Sub

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub

Private Sub txtAge_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtAge.KeyPress
Dim allowedChars As String = "0123456789"

If allowedChars.IndexOf(e.KeyChar) = -1 Then

e.Handled = True
End If

End Sub

Private Sub txtHeight_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtHeight.KeyPress
Dim allowedChars As String = "0123456789"

If allowedChars.IndexOf(e.KeyChar) = -1 Then

e.Handled = True
End If

End Sub

Private Sub txtWeight_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtWeight.KeyPress
Dim allowedChars As String = "0123456789"

If allowedChars.IndexOf(e.KeyChar) = -1 Then

e.Handled = True
End If

End Sub

Private Sub txtFirst_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtFirst.KeyPress
Try
If e.KeyChar = vbBack Then Return
If Not Char.IsLetter(e.KeyChar) Then e.KeyChar = Nothing

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub txtMiddle_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtMiddle.KeyPress
Try
If e.KeyChar = vbBack Then Return
If Not Char.IsLetter(e.KeyChar) Then e.KeyChar = Nothing

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub txtLast_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtLast.KeyPress
Try
If e.KeyChar = vbBack Then Return
If Not Char.IsLetter(e.KeyChar) Then e.KeyChar = Nothing

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub txtEdu_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtEdu.KeyPress
Try
If e.KeyChar = vbBack Then Return
If Not Char.IsLetter(e.KeyChar) Then e.KeyChar = Nothing

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub txtSex_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSex.KeyPress
Try
If e.KeyChar = vbBack Then Return
If Not Char.IsLetter(e.KeyChar) Then e.KeyChar = Nothing

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Private Sub txtDob_TextChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtDob.KeyPress

Dim allowedChars As String = "0123456789/.-,"

If allowedChars.IndexOf(e.KeyChar) = -1 Then

e.Handled = True
End If

End Sub
End Class

Srini
Author: srini             
Posted Date: September 29, 2010     Points: 5   

Sir, i need to generate sequence numbers in textbox,while loading the form everytime like 1,2,3,4,5,6,7 and so on..... And also save the details of all including Sno(textbox number) in SQL Server 2005 database

Srini
Author: Ramesh durai             
Posted Date: September 29, 2010     Points: 5   


use this page load coding with ur desire alteration

Private Sub Student_Form_Detail_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Me.DevelopTableAdapter.Fill(Me.DevDataSet5.develop)
conn = New SqlConnection("Data Source=.;Initial Catalog=Dev;Integrated Security=True")

da=new SqlDataAdapter("select count(*) as max from develop",conn);
Ds = new DataSet();
Da.Fill(Ds);
textbox1.text=convert.ToInt16(DS.Tables[0].Rows[0]["max"].toString())+1;
End Sub

Ramesh durai
Author: srini             
Posted Date: September 29, 2010     Points: 5   

Sir,Please reply soon....

Srini
Author: srini             
Posted Date: September 29, 2010     Points: 5   

Sir it shows Identifier excepted on this line,

textbox1.text=convert.ToInt16(DS.Tables[0].Rows[0]["max"].toString())+1;

Error on Tables[0]

Srini
Author: Ramesh durai             
Posted Date: September 29, 2010     Points: 5   

if You feel free send ur pages and db script to my mail id . i will give solution today late evening.


Ramesh durai
Author: srini             
Posted Date: September 29, 2010     Points: 5   

Ok sir. But send me before 6 sir. Please, Then only i can go to my home sir.

Srini
Author: srini             
Posted Date: September 29, 2010     Points: 5   

can u able to accept my invite now on Gtalk sir?

Srini
Author: Ramesh durai             
Posted Date: September 29, 2010     Points: 5   

ok

Ramesh durai
Author: srini             
Posted Date: September 29, 2010     Points: 5   

Ok sir. U send. I will manage. But accept my invitation on Gtalk sir. I will send my files through Gtalk sir.

Srini
Author: srini             
Posted Date: September 29, 2010     Points: 5   

Sent to ur gmail id sir. Please check it.

Srini
Author: srini             
Posted Date: September 29, 2010     Points: 5   

Hello Sir. Did you send the coding to my id sir? Didn't get yet!

Srini
Author: Manoranjan Sahoo             
Posted Date: September 30, 2010     Points: 5   

can you explain what you want to show exactly?
means : you want to show the number as the serial number of student or only just random number?
Please let me know the problem show that i can help you out.

Thank You.


Join My Site : http://dotnetsquare.com/
Author: srini             
Posted Date: September 30, 2010     Points: 5   

I just want to show the serial number of the student,while loading the form everytime(like 1,2,3,4,5,6,and so on) . That's it. I am using sqlserver 2005 as a back end.

Srini
Author: srini             
Posted Date: October 01, 2010     Points: 5   

I just want to show the serial number of the student,while loading the form everytime(like 1,2,3,4,5,6,and so on) . That's it. I am using sqlserver 2005 as a back end.

Srini
Author: Manoranjan Sahoo             
Posted Date: October 01, 2010     Points: 5   

Do you save the serial number into database? or only want to display?
if you want to display only then just use below query to fetch serial number from database :

select (count(*)+1) from TableName

and then set the above result into the textbox which is used for serial number.

Thank You.

If you have any problem then let me know with description.

Thank You.

Join My Site : http://dotnetsquare.com/
Author: Santosh             
Posted Date: October 05, 2010     Points: 5   

hi srini
wheather ur problem has solved or not??
if not then follow below process.

step

1. Drag a textbox called(txtslno) into ur screen.

2. set the visible properties is false

3.page load just call this method FillSLno()

4. write the below method

Private Sub FillSLno()
Dim objDS As New DataSet()
Dim objda As New SqlDataAdapter("SELECT COUNT(*) AS 'COUNT' FROM Student_m", conn)
objda.Fill(objDS)
txtSlno.Text = CInt(objDS.Tables(0).Rows(0).Item("COUNT").ToString) + 1
End Sub

5. after that u just add txtSlno.Text value as a slno in ur insert command and insert into database.


hope this will hepl u .
if any problem ,let me know..


Regards
Santosh




Author: swathi             
Posted Date: October 05, 2010     Points: 5   

Hi..you can set autoincrement option to sno column..

Regards
Swathi

Author: ASPEvil             
Posted Date: October 23, 2010     Points: 5   

First create another table in your database which will keep these incremented data, so every time the form will be loaded, it will show the incremented number from the last time loaded number whether the form had been closed or continuing

Next, at the very first just manually insert the value "0" in that table

Next, read this "0" from the database and display it in the textbox control

Then, write the following code to display incremented numbers:-

TextBox1.Text=CInt(TextBox1.Text)+1

And whenever you will insert the currently incremented value from the textbox control to the database with the other values, then don't forget to increment the table's(which is containing the incremented values) value by 1, each time.

Author: srini             
Posted Date: October 25, 2010     Points: 5   

Thank you for your response. I did that task already. I have another question. Actually i have done one vb.net windows application called "Register entry value". In that appl,i want to store the details into SQL server 2005. I done this,but if i am putting my appl(.exe only)and database backup into an another machine,it shows Error on "Server name/Instance specified"

Srini


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend