How to add value from database to combobox

To add data from mysql table to combobox in c#

1. add preferences for mysql , to add preferences to visual studio view this article
2.double click in form1 and write the code below
Private void Form1_load(Object sender,EventArgs e){
MysqlConnection conn = New MysqlConnection();
MysqlCommand comm = New MysqlCommand();
MysqlAdapter adapat = New MysqlAdapter;
MysqlDataReader reader;
string Connection = “Server=YourSeverName ; user = youruser;database = yourdatabase;”;
conn = new MysqlConnection(Connection);
comm = conn.CreateCommand();
comm.CommandText  = “select column_name from tablename;”;
adapat = New MysqlDataAdapter(comm);
reader = comm.ExecuteReader();
while (reader.Read()){
string skode = reader.GetString(“Kodebarang”);

Leave a Reply