Reputation: 69
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
Upvotes: 0
Views: 6361
Reputation: 69
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()
Upvotes: 0
Reputation: 3156
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#")
Upvotes: 1