Results 1 to 8 of 8

Thread: Auto Generate Textbox

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2012
    Posts
    94

    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

  2. #2
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  3. #3
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: Auto Generate Textbox

    vb Code:
    1. Public Sub serialnogenerate()
    2.    connect()
    3.    sqlquery = "select c_slno from newconnection"
    4.    cmd = New SqlCommand(sqlquery, con)
    5.    dr = cmd.ExecuteReader
    6.       While dr.Read
    7.          a = dr(0)
    8.       End While
    9.  
    10.    Dim srlnotxt As Integer
    11.  
    12.         If Integer.TryParse(CStr(CDbl(a) + 1), srlnotxt) Then
    13.               serialnotxt.Text = srlnotxt.tostring
    14.         End If
    15.  
    16.    con.Close()
    17. End Sub


    Is this what you were after?

  4. #4
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: Auto Generate Textbox

    Wait a minute, apologies, I misread the OP.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2012
    Posts
    94

    Re: Auto Generate Textbox

    i have try with your code it still not displaying the the auto generate serial no in the textbox

  6. #6
    Fanatic Member proneal's Avatar
    Join Date
    May 2011
    Posts
    762

    Re: Auto Generate Textbox

    Quote Originally Posted by kiki2012 View Post
    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!

  7. #7
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    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

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Mar 2012
    Posts
    94

    Exclamation 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
  •  



Click Here to Expand Forum to Full Width