Re: Auto Generate Textbox
What do you expect from this line?
serialnotxt.Text = a + 1
That will go through all the records, substituting the value of the textbox each iteration so you will get only the last one. And since you are adding the "1", are those numbers? do you want to add to the quantity or expect to add a 1 to the string?
Your connect() sub may affect the rest of the procedure, I don't know.
Note: enclose your code in CODE tags, not QUOTE ones.
Re: Auto Generate Textbox
vb Code:
Public Sub serialnogenerate()
connect()
sqlquery = "select c_slno from newconnection"
cmd = New SqlCommand(sqlquery, con)
dr = cmd.ExecuteReader
While dr.Read
a = dr(0)
End While
Dim srlnotxt As Integer
If Integer.TryParse(CStr(CDbl(a) + 1), srlnotxt) Then
serialnotxt.Text = srlnotxt.tostring
End If
con.Close()
End Sub
Is this what you were after?
Re: Auto Generate Textbox
Wait a minute, apologies, I misread the OP.
Re: Auto Generate Textbox
i have try with your code it still not displaying the the auto generate serial no in the textbox
Re: Auto Generate Textbox
Quote:
Originally Posted by
kiki2012
i have try with your code it still not displaying the the auto generate serial no in the textbox
LOL< please refer to my post #4
You shouldn't have even considered my code example.
I hope you sort it out!
God Luck!
Re: Auto Generate Textbox
Could you elaborate on what you want? It is not clear
Re: Auto Generate Textbox
Sir,
Here is the code which i want to display the auto generate next number from sql server 2005 to vb.net 2005 textbox
Code:
Imports System.Data.SqlClient
Public Class NewConnection
Dim con As New SqlConnection("Data Source=PC;Initial Catalog=GasAgency;Integrated Security=True;Pooling=False")
Dim sqlquery As String
Dim cmd As SqlCommand
Dim dr As SqlDataReader
Dim a As Integer
Public Sub serialnogenerate()
con.Open()
sqlquery = "select c_slno from newconnection"
cmd = New SqlCommand(sqlquery, con)
dr = cmd.ExecuteReader
While dr.Read
a = dr(0)
End While
serialnotxt.Text = a + 1
con.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
serialnotxt.Text = ""
End Sub