Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Windows Form and MySQL C#

$
0
0

Hey 

I'm trying to make a application can show MySQL Tables -> rows using

dataGridView1.DataSource

But it's don't show anything when i click the button :/ 

i tested if it's send Query and it's work good but it's not showing MySQL Tables ( rows ) btw this is my code : 

if (this.OpenConnection() == true)
                {
                    try
                    {
                        string sql = "SELECT * FROM `" + table.Text + "`"; // set query to fetch data "Select * from  tabelname";
                        DataSet s = new DataSet();
                        MySqlDataAdapter ds = new MySqlDataAdapter(sql, connection);
                        MySqlCommandBuilder k = new MySqlCommandBuilder(ds);
                        ds.Fill(s, table.Text);
                        dataGridView1.DataSource = s.Tables[table.Text];
                        s.Dispose();
                        this.connection.Close();

                    }
                    catch (Exception z)
                    {
                        using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\ProgramData\SAPMySQL\logs.txt", true))
                        {
                            string og;
                            og = "[MySQL Error]:" + z.Message;
                            file.WriteLine(thisDay.ToString() + og);
                            file.WriteLine("");
                            if (og == "[MySQL Error]:Character set 'utf16' is not supported")
                            {
                                MessageBox.Show("All Rows now showen!", "SAP MySQL: Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                            else
                            {
                                MessageBox.Show("Fatal Error: 0x0DDF5FFt Unable to Load Query\n" + og, "SAP MySQL: Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }

Thank You in advence :)

Yassine

 

Viewing all articles
Browse latest Browse all 2535

Trending Articles



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