Hi i've created a class which name is testclass.cls

Inside of testclass.cls i created this code

public void Insert(string materialSize, string KgPermetre, string PricePerCut, string MaterialType, string LineColour)
            SqlConnection objcon = new SqlConnection(Cls_Connection.srConnectionString);
            SqlCommand cmd = new SqlCommand("sp_MaterialSize", objcon) { CommandType = CommandType.StoredProcedure };
            cmd.Parameters.AddWithValue("action", "Insert");
            cmd.Parameters.AddWithValue("MaterialSizeId", "");
            cmd.Parameters.AddWithValue("MaterialSize", materialSize);
            cmd.Parameters.AddWithValue("KgPerMetre", KgPermetre);
            cmd.Parameters.AddWithValue("PricePerCut", PricePerCut);
            cmd.Parameters.AddWithValue("MaterialType", MaterialType);
            cmd.Parameters.AddWithValue("LineColour", LineColour);
            return false;

How can i call this calss into my winform i try

testclassInsert(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text);

but i got error please help.

check the namespace of your class, the namespace in your winforms must the same with the namespace in your class, if not you must: Using ClassNameSpace;

it must be on same project also.

Wouldn't you need to instantiate the class first and then call the .Insert() method off the instanciated object? Obviously we can't see the full code so thats a guess but it could be the case.


TestClass TS = new TestClass(); //With any constructor you use
This question has already been answered. Start a new discussion instead.