saving data from 2nd form to the same master table in win form application

ravi kumar 331 Reputation points
2020-12-12T06:40:21.617+00:00

I have two winforms where form 1 is used to enter data from first seven fields and other forms is used to enter for last three fields , where i have the table stored in MSSQL server ,Now when i try to save the last three fields i am getting below " invalid column error , but actually it is present in my sql table , i am very new to C# , kindly help me :

Code for saving data in second form:

private void Btnrejsave_Click(object sender, EventArgs e)  
        {  
  
            SqlConnection con = new SqlConnection(cs);  
            SqlCommand cmd;  
            con.Open();  
            string s = "select * from RejReason where SpoolId = (@p4) insert into IP_Spools(RejectReason1,RejectReason2,RejectReason3) values(@p1,@p2,@p3)";  
            cmd = new SqlCommand(s, con);  
            cmd.Parameters.AddWithValue("@p1", rejectReason1ComboBox.Text);  
            cmd.Parameters.AddWithValue("@p2", rejectReason2ComboBox.Text);  
            cmd.Parameters.AddWithValue("@p3", rejectReason3ComboBox.Text);  
            cmd.Parameters.AddWithValue("@p4", IDtextbox.Text);  
            cmd.CommandType = CommandType.Text;  
            int i = cmd.ExecuteNonQuery();  
            con.Close();  
  
        }  

And the error i am getting :

{"Invalid column name 'SpoolId'."}  

but the server table has that column:

47557-image.png

47460-image.png

Developer technologies | Windows Forms
Developer technologies | Transact-SQL
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Viorel 125.8K Reputation points
    2020-12-12T08:28:24.783+00:00

    If your first form inserts to IP_Spools (not to RejReason) and IDTextbox is the ID of new row, then maybe try another statement:

    string s = "update IP_Spools set RejectReason1 = @p1, RejectReason2 = @p2, RejectReason3 = @p3 where SpoolId = @p4";
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. ravi kumar 331 Reputation points
    2020-12-12T08:36:21.917+00:00

    Thank you so much it helped

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.