Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1451

Maintaining leading zeros (no replies)

$
0
0
All the primary keys in my database are zerofilled, but when I go to import them to a listbox (as shown below), they lose the leading zeros. How can I maintain the leading zeros?

Public Sub ListboxQuery(ByVal Query As String, ByVal ResultObject As Object, ByVal ResultDisplay As String, ByVal ResultValue As String)
'queries the database for a 1- or 2-column list of values to display in a listbox
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myData As New DataTable

Try
Conn.Open()
Try
myCommand.Connection = Conn
myCommand.CommandText = Query
myAdapter.SelectCommand = myCommand
myAdapter.Fill(myData)
ResultObject.DataSource = myData
ResultObject.displaymember = ResultDisplay
ResultObject.valuemember = ResultValue
Catch myerror As MySqlException
MsgBox("Error reading from the database: " & myerror.Message)
End Try
Catch myerror As MySqlException
MessageBox.Show("Error connecting to database: " & myerror.Message)
Finally
If Conn.State <> ConnectionState.Closed Then Conn.Close()
End Try
'deselects or unchecks the listbox
If TypeOf ResultObject Is ComboBox Then
ResultObject.selectedindex = -1
ResultObject.text = ""
Else
For i As Integer = 0 To (ResultObject.selecteditems.count - 1)
If TypeOf ResultObject Is CheckedListBox Then
ResultObject.setitemchecked(i, False)
End If
ResultObject.setselected(i, False)

Next
End If

End Sub

Viewing all articles
Browse latest Browse all 1451

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>