0

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

1
  • Do not add formatting to tables, it is rarely a good idea as it will lead to confusion about data types. Commented Oct 31, 2012 at 10:31

2 Answers 2

1

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#")
Sign up to request clarification or add additional context in comments.

1 Comment

@user692495 It seems that this answer has solved your problem, if this is the case, you can accept the answer. The details are in the faq stackoverflow.com/faq#howtoask
0
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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.