Wierd double quote being generated by C# going into SQL syntax

Could anyone point out what I’m doing wrong, I’m getting an error back in SQL saying Syntax error near ” at line 1

I have tried everything and can’t seem to get rid of it ?

This is the code I’m Using –

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        MySqlConnection conn;
        MySqlConnection conn1;
        bool connection = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            this.toolStripStatusLabel1.Text = "Initialising";
            db_connect();

        }

        private void db_connect()
        {

            string mydbconn = "server=localhost;user id=root;password=lap;database=test;";
            string mydbconn1 = "server=localhost;user id=root;password=lap;database=test;";

            try
            {

                conn = new MySqlConnection(mydbconn);
                conn1 = new MySqlConnection(mydbconn1);

                conn.Open();
                conn1.Open();
                this.toolStripStatusLabel1.Text = "Connected";
                connection = true;
                if (connection == true)
                {
                    read_data();
                }

            }

            catch (Exception ex)
            {
                this.toolStripStatusLabel1.Text = "WRONG";
                connection = false;
            }
        }

        private void read_data()
        {

            string sql = "SELECT first_name, last_name FROM dan";

            MySqlCommand cmd = new MySqlCommand(sql, conn);

            MySqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {

                string newsql = "REPLACE INTO dan1 (first_name, last_name) values";

                newsql += "(";

                for (int i = 0; i < 2; i++)
                {

                    newsql += reader.GetString(i);

                }

               // System.Console.WriteLine(newsql);

                int res = 0;
                MySqlCommand cmd1 = new MySqlCommand(newsql, conn1);

                try
                {

                    res = cmd1.ExecuteNonQuery();
                    this.richTextBox1.Text = "copying";

                }

                catch (MySqlException ex)
                {

                    this.richTextBox1.Text = ex.Message;

                }

            }

        }
    }
}


Download wierd.double.quote.being.generated.by.c.going.into.sql.syntax.zip
Direct Link


Download


Download wierd.double.quote.being.generated.by.c.going.into.sql.syntax.zip
Mediafire


Download


Download wierd.double.quote.being.generated.by.c.going.into.sql.syntax.zip
Embedupload


Download


Download wierd.double.quote.being.generated.by.c.going.into.sql.syntax.zip
Chayfile


Download


Download wierd.double.quote.being.generated.by.c.going.into.sql.syntax.zip
File.up09.com


Download

Both comments and pings are currently closed.

Comments are closed.