Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The error is exactly what it says. You cannot use <code>con</code> in your initialization of <code>da</code> because it will only be created during an instance creation. You will need to create <code>con</code> as <code>static</code> or put your initialization lines in your constructor.</p> <p><strong>HOWEVER</strong>, you should probably not do this in practice as you are just asking for somebody to open a <code>SqlConnection</code> and leave it open. You should probably fall more into the practice of creating your connections using a <code>using</code> block to take advantage of the disposing pattern</p> <p>Static:</p> <pre><code>public partial class Form1 : Form { static SqlConnection con = new SqlConnection(@"Data Source=TALY-PC;Initial Catalog=Katalogi;Integrated Security=True;Pooling=False"); SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM tblArtikujt", con); DataSet dsl = new DataSet(); public Form1() { InitializeComponent(); } </code></pre> <p>Or instantiation in the constructor:</p> <pre><code>public partial class Form1 : Form { SqlConnection con; SqlDataAdapter da; DataSet dsl; public Form1() { InitializeComponent(); con = new SqlConnection(@"Data Source=TALY-PC;Initial Catalog=Katalogi;Integrated Security=True;Pooling=False"); da = new SqlDataAdapter("SELECT * FROM tblArtikujt", con); dsl = new DataSet(); } } </code></pre> <p>I will let you <a href="http://msdn.microsoft.com/en-us/library/yh598w02%28v=vs.80%29.aspx" rel="nofollow">research the using block yourself</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload