Click here to Skip to main content
16,011,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My program Reads variables from DB Successfully

But i have a problem in inserting data into it
i don't know why ?
i use this code in more programs and it works good

C# Class Code
C#
class Gesture
    {
        //Sql DB Connection
        SqlConnection con1 = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Amr Khalid\Documents\HandGestures.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");

         public void Addgesture(int i , string blue, string red, string green, string yellow, string magenta , string control)
        {
            SqlCommand mycom2 = new SqlCommand();
            mycom2.Connection = con1;
            mycom2.CommandType = CommandType.StoredProcedure;
            mycom2.CommandText = "AddGesture";
            mycom2.Parameters.AddWithValue("@int", i);
            mycom2.Parameters.AddWithValue("@blue", blue);
            mycom2.Parameters.AddWithValue("@red", red);
            mycom2.Parameters.AddWithValue("@green", green);
            mycom2.Parameters.AddWithValue("@yellow", yellow);
            mycom2.Parameters.AddWithValue("@magenta", magenta);
            mycom2.Parameters.AddWithValue("@Control", control);
            con1.Open();
            mycom2.ExecuteNonQuery();
            con1.Close();

        }
}

C# Program Code
C#
int i = 77;
string control = comboBox1.Items.ToString();
Gesture newg = new Gesture();
newg.Addgesture(i, FBlue2, FRed2, FGreen2, FYellow2, FMagenta2, control);


StoredProcedure SQL code

SQL
ALTER PROCEDURE AddGesture

    @int int ,@blue varchar(50) , @red varchar(50) ,@green varchar(50) ,@yellow varchar(50) , @magenta varchar(50) , @Control varchar(50)

AS


    Insert into Gesture values (@int ,@blue,@red,@green,@yellow,@magenta,@Control)

    RETURN



>>>>>>>>>>>>>>>>>
C#



i have the problem in
mycom2.ExecuteNonQuery();

The error is
Invalid object name 'Gesture'.

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 13-Jul-12 4:09am
v4

It is complaining that the database your are connected to does not have a table called "gesture".

Check you are connected to the correct database, and that your tables name is correct.

BTW it is also a very good idea to name the fields that you are inserting into: that way changes to your DB won't mess up your inserts and thus your database.
 
Share this answer
 
Comments
AshishChaudha 13-Jul-12 10:12am    
good answer my 5!
AmrKhalid 13-Jul-12 10:15am    
Thanx :)

i hate when the problem is So Small
and i can't find it :(

The Table name is right in My Select StoredProcedure
and i wrote it false there in Add

Thanx OriginalGriff :)
OriginalGriff 13-Jul-12 10:44am    
:laugh: I do it all the time - I read what I meant to write!
You're welcome!
Check your table name Gesture in your Database whether it exists or not.

Invalid object name 'Gesture'.
This error comes when the tablename does not exist.

Please check it out.

Thanks
Ashish
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900