-
Mar 27th, 2012, 01:23 PM
#1
Thread Starter
Lively Member
Auto Generate Textbox
dear Sir,
I have tried to populate the textbox from auto generate serial no column of sql server 2005 with this code below, but it does not work, the textbox still show empty.
So kindly help me how to display the textbox with the data retrieve from sql server 2005
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
serialnotxt.Text = a + 1
con.Close()
End Sub
-
Mar 27th, 2012, 01:30 PM
#2
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.
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Mar 27th, 2012, 03:01 PM
#3
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?
-
Mar 27th, 2012, 03:26 PM
#4
Re: Auto Generate Textbox
Wait a minute, apologies, I misread the OP.
-
Mar 28th, 2012, 04:37 AM
#5
Thread Starter
Lively Member
Re: Auto Generate Textbox
i have try with your code it still not displaying the the auto generate serial no in the textbox
-
Mar 28th, 2012, 11:08 AM
#6
Re: Auto Generate Textbox
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!
-
Mar 28th, 2012, 11:21 AM
#7
Re: Auto Generate Textbox
Could you elaborate on what you want? It is not clear
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Mar 31st, 2012, 08:32 AM
#8
Thread Starter
Lively Member
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|