简体   繁体   中英

View data from database using textbox

I have made some format in my access database,but when i try to view in textbox it not view the value using the format that i have set it. I use vb.net as a programming language and ms access as a database

Access database :

Field Name : sampleID Data Type : AutoNumber Format : "000000"

VB.net code :

sql = "SELECT * FROM Cleaning"
    cmd = New OleDbCommand(sql, cnnOLEDB)
    cnnOLEDB.Open()

    Dim dr As OleDbDataReader
    dr = cmd.ExecuteReader()
    While dr.Read()

        txtSampleID.Text = dr("sampleID").ToString()

    End While
    dr.Close()

output in textbox after run program= 14

the actual output that i want to view is 000014

That's because the value being returned from sql is an integer, not a string. You can change your code to re-format it the way you want:

    txtSampleID.Text = Cint(dr("sampleID")).ToString("00000#")
sql = "SELECT * FROM Cleaning"
cmd = New OleDbCommand(sql, cnnOLEDB)
cnnOLEDB.Open()

Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()
While dr.Read()

   txtSampleID.Text = Cint(dr("sampleID")).ToString("00000#")
End While
dr.Close()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM