0

Good afternoon Everybody,

I need help - I want get row ID from datagridview in Form1 to the sqltable. But button for execute i have in Form2. And I don´t know how to connect Form1 and Form2. Example - I want write value in to the sql table - first is name and I want searching via ID. But Visual Studio has written - In order to use a non-static field, method, or property, you must first create an object instance. Can you help me?

    {
        
        string source4 = (@"Data Source=SRV01\SQLEXPRESS;Initial Catalog=ArburgSoft;Integrated Security=True");
       
        SqlConnection con4 = new SqlConnection(source4);
        con4.Open();
        

      
        cmd4 = new SqlCommand("Update Souhrn Set program=@program where Id=" + Form1.dataGridView1.SelectedRows[0].Cells[0].Value.ToString() + , "");
       
        `
Maverick26
  • 11
  • 1
  • Your code has a bunch of issues: Your main one is `Form1` is the name of the class not an object, you should use `this` or whatever reference you have to the `Form1` object. Also, **use proper parameterization of queries** otherwise you are at risk of injection attacks and syntax errors. You should dispose the connection with `using` and store the connection string in a settings file, not hard-coded in. – Charlieface Apr 22 '21 at 12:07
  • Does that code even compile? This looks weird `Value.ToString() + , "")` – Cleptus Apr 22 '21 at 12:17

0 Answers0