Insert Data into SQL Server database - Winforms
<p>I am trying to insert the data once user clicks on button "druk". The connection string does not seem to be set properly as the debug stop at this point and does not go further. I have the Data Connection set and connected. I have removed and replaced username from connection string due to security reasons.</p>

<ul>
<li>Server: <code>s59.hekko.net.pl</code> </li>
<li>Database name: <code>truex2_kuba</code></li>
<li>Database table: <code>barcode</code> </li>
</ul>

<p>Code:</p>

<pre><code>private void druk_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection();
    con.ConnectionString = "DataSource=s59.hekko.net.pl; Initial Catalog=username; Integrated security=true";
    con.Open();

    SqlCommand cmd = new SqlCommand();
    cmd.CommandText = "insert into [barcode]values(@class, @tree, @type, @amount, @length, @width, @square)";

    cmd.Parameters.AddWithValue("@class", klasa.Text);
    cmd.Parameters.AddWithValue("@tree", gatunek.Text);
    cmd.Parameters.AddWithValue("@type", rodzaj.Text);
    cmd.Parameters.AddWithValue("@amount", amount.Text);
    cmd.Parameters.AddWithValue("@length", length.Text);
    cmd.Parameters.AddWithValue("@width", width.Text);
    cmd.Parameters.AddWithValue("@square", textBox1.Text);

    int a = cmd.ExecuteNonQuery();

    if (a &gt; 0)
    {
        MessageBox.Show("Zapisane do raportu");
    }
}
</code></pre>