1,105,399 Community Members

How to call this class in c#

Member Avatar
ryan311
Posting Whiz in Training
294 posts since Jul 2008
Reputation Points: -7 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

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);
            objcon.Open();
            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);
            cmd.ExecuteNonQuery();
            objcon.Close();
            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.

Member Avatar
notconfirmed
Newbie Poster
14 posts since Apr 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
ryan311
Posting Whiz in Training
294 posts since Jul 2008
Reputation Points: -7 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

its had the same namespace. how can i call it?

Member Avatar
Mike Askew
Posting Shark
927 posts since Nov 2010
Reputation Points: 129 [?]
Q&As Helped to Solve: 85 [?]
Skill Endorsements: 25 [?]
Featured
 
0
 

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.

I.e

TestClass TS = new TestClass(); //With any constructor you use
TS.Insert(Params...);
Member Avatar
ryan311
Posting Whiz in Training
294 posts since Jul 2008
Reputation Points: -7 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 0 [?]
 
0
 

Mikeisme thank you so much :)

Question Answered as of 1 Year Ago by Mike Askew and notconfirmed
Member Avatar
Mike Askew
Posting Shark
927 posts since Nov 2010
Reputation Points: 129 [?]
Q&As Helped to Solve: 85 [?]
Skill Endorsements: 25 [?]
Featured
 
0
 

Your welcome :)

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article