Reinhardt
Reinhardt

Reputation: 143

Accessing to the database Integer type

i have a problem here. I already create a textbox that connect to the database in windows app, but this textbox is string type and is working successfully, on the second form i created an array of textboxes that connect to the database, but this time is int type. how do i access that textbox to the database that int type?

Here is my code for second form, i using an array of textboxes:

OleDbDataReader dReader;
        OleDbConnection conn = new OleDbConnection(connectionString);
        conn.Open();
        OleDbCommand cmd = new OleDbCommand("SELECT DISTINCT [Code] FROM [Data] ORDER BY [Code] ASC", conn);
        dReader = cmd.ExecuteReader();
        AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();

        while (dReader.Read())
        {
            namesCollection.Add(dReader.GetInt32(dReader.GetOrdinal("Code"));
        }

        textBoxCodeContainer[0][0].AutoCompleteMode = AutoCompleteMode.Suggest;
        textBoxCodeContainer[0][0].AutoCompleteSource = AutoCompleteSource.CustomSource;
        textBoxCodeContainer[0][0].AutoCompleteCustomSource = namesCollection;

        dReader.Close();
        conn.Close();

Somehow,the while (dReader.Read()) is error, i dont know how to solve this, can anyone help me please? Thanks

Upvotes: 0

Views: 124

Answers (1)

Grant Winney
Grant Winney

Reputation: 66439

According to MSDN, the only Add method for AutoCompleteStringCollection is:

public int Add(string value)

So try converting your integer to a string before adding it to the collection:

namesCollection.Add(Convert.ToString(dReader.GetInt32(dReader.GetOrdinal("Code")));

Upvotes: 1

Related Questions