First off this is my first attempt at C#. My issue is, regardless of me using datatables, lists, or mysqldatareader; the query only returns one result and only the last result of the table.
My Table Values are(Col names first): Index City 1 Paris 2 London
My C# last code attempt was:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace MySQL_Sample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//MySql connections
MySqlConnection connection;
string host;
string db;
string uid;
string pass;
host = "localhost";
db = "sample";
uid = "root";
pass = "";
string ConnectionString = "SERVER=" + host + ";" + "DATABASE=" + db + ";" + "UID=" + uid + ";" + "PASSWORD=" + pass + ";";
connection = new MySqlConnection(ConnectionString);
connection.Open();
//MySql Commands
string sql = "SELECT * FROM table1";
MySqlCommand cmd = new MySqlCommand(sql, connection);
MySqlDataReader rdr = cmd.ExecuteReader();
//MySql Call back
while(rdr.Read())
{
DataTxtBox.Text = rdr[0].ToString() + " | " + rdr[1].ToString();
}
}
}
}