none
"No value given for one or more required parameters." Someone Help

    Question

  • Hello.

    im use this code for fill the mydatabase. but its not work. im really confused .

    OleDbConnection oled= new OleDbConnection();
            oled.ConnectionString= @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Mohammad\Documents\Visual Studio 2008\Projects\WebSite3\hamayesh.accdb";
            oled.Open();

            OleDbDataAdapter oled_dataadaptr = new OleDbDataAdapter("INSERT INTO [personal_info] (Nam, Surname, [E-mail], [Phone-number], Company, [Company-Adress], Website, egamat)VALUES (@name,@surename,@email,@phone,@company,@companyname,@website,@egamat)", oled);
            //oled_dataadaptr = new OleDbDataAdapter("SELECT * FROM personal_info", oled);
           
            OleDbCommandBuilder oled_comandbuilder= new OleDbCommandBuilder(oled_dataadaptr);
            DataTable oled_datatable = new DataTable();
            oled_dataadaptr.Fill(oled_datatable);
            int oled_rowposition =0;

           
            DataRow oled_datarow = oled_datatable.NewRow();
            oled_datarow["@name"] = TextBoxName.Text;
            oled_datarow["@surname"] = TextBoxSurename.Text;
            oled_datarow["@email"] = TextBoxemail.Text;
            oled_datarow["@phone"] = TextBoxphone.Text;
            oled_datarow["@ompany"] = TextBoxcompany.Text;
            oled_datarow["@Companyname"] = TextBoxcompanyadress.Text;
            oled_datarow["@website"] = TextBoxAdress.Text;
            oled_datarow["@egamat"] = TextBoxegamat.Text;

            oled_datatable.Rows.Add(oled_datarow);
            oled_dataadaptr.Update(oled_datatable);
            oled_rowposition = oled_datatable.Rows.Count -1;
           
            oled.Close();

    • Moved by Alex LiangModerator Tuesday, June 01, 2010 8:11 AM Move to a more related forum (From:Visual Basic General)
    Sunday, May 30, 2010 1:00 PM

Answers

  • Hi Bouki,

    Please try this:

    OleDbConnection oled= new OleDbConnection();
            oled.ConnectionString= @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Mohammad\Documents\Visual Studio 2008\Projects\WebSite3\hamayesh.accdb";

            OleDbCommand oledbcommand = new OleDbCommand();
            oledbcommand.Connection = oled;
            oledbcommand.CommandText = "INSERT INTO [personal_info] (Name, Surname, [E-mail], [Phone-number], Company, [Company-Adress], Website, egamat) VALUES (?,?,?,?,?,?,?,?)";

            oledbcommand.Parameters.Clear();
            oledbcommand.Parameters.AddWithValue("@name", TextBoxName.Text);
            oledbcommand.Parameters.AddWithValue("@surename", TextBoxSurename.Text);
            oledbcommand.Parameters.AddWithValue("@email", TextBoxemail.Text);
            oledbcommand.Parameters.AddWithValue("@phone", TextBoxphone.Text);
            oledbcommand.Parameters.AddWithValue("@company", TextBoxcompany.Text);
            oledbcommand.Parameters.AddWithValue("@companyname", TextBoxcompanyadress.Text);
            oledbcommand.Parameters.AddWithValue("@website", TextBoxAdress.Text);
            oledbcommand.Parameters.AddWithValue("@egamat", TextBoxegamat.Text);

            oledbcommand.Prepare();
            oled.Open();
            oledbcommand.ExecuteNonQuery();
            oled.Close();

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, June 01, 2010 8:10 AM
    Moderator

All replies

  • yes

    its Name.

    but i think its not problem!

    this error ecured when i run the project

    No value given for one or more required parameters.

     

    Sunday, May 30, 2010 1:20 PM
  • ok, lol ! why are you giving INSERT command there man ? it should be SELECT command.

    Thanks

    My blog
    Living on Earth may be expensive, but did you know that it includes a free trip around the sun? Isn't that worth it?
    Sunday, May 30, 2010 1:22 PM
  • are you sure?

    but i want insert into my table?

    can you fix it?

    please fix this ...... error.

    Sunday, May 30, 2010 1:28 PM
  • do you have to use dataTable object etc ? are you binding it to anything later ? you can do insert without it like this..

                OleDbConnection oled = new OleDbConnection();
                oled.ConnectionString = @"connection string";

                OleDbCommand oled_command = new OleDbCommand();
                oled_command.Connection = oled;
                oled_command.CommandText = "INSERT INTO [personal_info] (Name, Surname, [E-mail], [Phone-number], Company, [Company-Adress], Website, egamat)VALUES (@name,@surename,@email,@phone,@company,@companyname,@website,@egamat)";
               
                oled_command.Parameters.Clear();
                oled_command.Parameters.AddWithValue("@name", TextBoxName.Text);
                //add other values here
                //oled_command.Parameters.AddWithValue("@surname", TextBoxSurname.Text);
                //etc
                //
                //
                //
                oled_command.Prepare();
                oled.Open();
                oled_command.ExecuteNonQuery();
                oled.Close();


    Thanks

    My blog
    Living on Earth may be expensive, but did you know that it includes a free trip around the sun? Isn't that worth it?
    Sunday, May 30, 2010 1:44 PM
  • 'You omitted "e" here
    oled_datarow["@surEname"] = TextBoxSurename.Text;
    '....and omitted "C" here
           oled_datarow["@Company"] = TextBoxcompany.Text;
    

    The parameters for @Surname and @Company are wrong. Check for similar omissions.

     


    Only performance counts!
    Sunday, May 30, 2010 1:46 PM
  • thanks for your help.

    but its not worked.

    OleDbConnection oled= new OleDbConnection();
            oled.ConnectionString= @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Mohammad\Documents\Visual Studio 2008\Projects\WebSite3\hamayesh.accdb";

            OleDbCommand oledbcommand = new OleDbCommand();
            oledbcommand.Connection = oled;
            oledbcommand.CommandText = "INSERT INTO [personal_info] (Name, Surname, [E-mail], [Phone-number], Company, [Company-Adress], Website, egamat)VALUES (@name,@surename,@email,@phone,@company,@companyname,@website,@egamat)";

            oledbcommand.Parameters.Clear();
            oledbcommand.Parameters.AddWithValue("@name", TextBoxName.Text);
            oledbcommand.Parameters.AddWithValue("@surename", TextBoxSurename.Text);
            oledbcommand.Parameters.AddWithValue("@email", TextBoxemail.Text);
            oledbcommand.Parameters.AddWithValue("@phone", TextBoxphone.Text);
            oledbcommand.Parameters.AddWithValue("@company", TextBoxcompany.Text);
            oledbcommand.Parameters.AddWithValue("@companyname", TextBoxcompanyadress.Text);
            oledbcommand.Parameters.AddWithValue("@website", TextBoxAdress.Text);
            oledbcommand.Parameters.AddWithValue("@egamat", TextBoxegamat.Text);

            oledbcommand.Prepare();
            oled.Open();
            oledbcommand.ExecuteNonQuery();
            oled.Close();

    Sunday, May 30, 2010 2:18 PM
  • dear sylva.

    im fixed it but not work .

     

    Sunday, May 30, 2010 2:20 PM
  • What's the issue now Same error message?

    By the way this is Visual Basic General Forum and it appears that you're working on C#.


    Only performance counts!
    Sunday, May 30, 2010 2:25 PM
  • this error happen:

    "no value given for one or more required parameters"

    im working in C#.

    please help me.

    Sunday, May 30, 2010 2:34 PM
  • Why do you have "'@" in front of the Connectionstring (in VB we don't do that)? Secondly try changing the @name to @personName or something different.

    You must know that issues like this have no known solution other than a careful and patient reading between the lines.

     


    Only performance counts!
    Sunday, May 30, 2010 2:42 PM
  • im red it again. but i cant solve it.

     OleDbConnection oled= new OleDbConnection();
            oled.ConnectionString= @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Mohammad\Documents\Visual Studio 2008\Projects\WebSite3\hamayesh.accdb";

            OleDbDataAdapter oled_dataadaptr = new OleDbDataAdapter("INSERT INTO personal_info (Nam,Surname, [E-mail], [Phone-number], Company, [Company-Adress], Website, egamat)VALUES (@personnam, @surename, @email, @phone, @company, @companyname, @website, @egamat)", oled);
           
            OleDbCommandBuilder oled_comandbuilder = new OleDbCommandBuilder(oled_dataadaptr);
            DataTable oled_datatable = new DataTable();
            oled_dataadaptr.Fill(oled_datatable);
            int oled_rowposition = 0;


            DataRow oled_datarow = oled_datatable.NewRow();
            oled_datarow["@personnam"] = TextBoxName.Text;
            oled_datarow["@surename"] = TextBoxSurename.Text;
            oled_datarow["@email"] = TextBoxemail.Text;
            oled_datarow["@phone"] = TextBoxphone.Text;
            oled_datarow["@company"] = TextBoxcompany.Text;
            oled_datarow["@companyname"] = TextBoxcompanyadress.Text;
            oled_datarow["@website"] = TextBoxAdress.Text;
            oled_datarow["@egamat"] = TextBoxegamat.Text;

            oled_datatable.Rows.Add(oled_datarow);
            oled_dataadaptr.Update(oled_datatable);
            oled_rowposition = oled_datatable.Rows.Count - 1;

            oled.Close();

    error accured in this line:

    oled_dataadaptr.Fill(oled_datatable);

    error detail:

     

    No value given for one or more required parameters

    Sunday, May 30, 2010 2:57 PM
  • this error happen:

    "no value given for one or more required parameters"

    im working in C#.

    please help me.

    Hi Bouki,

    Please use the Visual C# forums.>>

    http://social.msdn.microsoft.com/Forums/en-US/category/visualcsharp

     

    or this one for the EXPRESS EDITION.>>

    http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/threads

     

    Regards,

    John

     


    Please see this thread for Vb.Net learning links.>> http://social.msdn.microsoft.com/Forums/en/vbgeneral/thread/549c8895-6780-42f8-878f-2138214fdeb4
    Sunday, May 30, 2010 8:07 PM
  • Hi Bouki,

    Please try this:

    OleDbConnection oled= new OleDbConnection();
            oled.ConnectionString= @"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Mohammad\Documents\Visual Studio 2008\Projects\WebSite3\hamayesh.accdb";

            OleDbCommand oledbcommand = new OleDbCommand();
            oledbcommand.Connection = oled;
            oledbcommand.CommandText = "INSERT INTO [personal_info] (Name, Surname, [E-mail], [Phone-number], Company, [Company-Adress], Website, egamat) VALUES (?,?,?,?,?,?,?,?)";

            oledbcommand.Parameters.Clear();
            oledbcommand.Parameters.AddWithValue("@name", TextBoxName.Text);
            oledbcommand.Parameters.AddWithValue("@surename", TextBoxSurename.Text);
            oledbcommand.Parameters.AddWithValue("@email", TextBoxemail.Text);
            oledbcommand.Parameters.AddWithValue("@phone", TextBoxphone.Text);
            oledbcommand.Parameters.AddWithValue("@company", TextBoxcompany.Text);
            oledbcommand.Parameters.AddWithValue("@companyname", TextBoxcompanyadress.Text);
            oledbcommand.Parameters.AddWithValue("@website", TextBoxAdress.Text);
            oledbcommand.Parameters.AddWithValue("@egamat", TextBoxegamat.Text);

            oledbcommand.Prepare();
            oled.Open();
            oledbcommand.ExecuteNonQuery();
            oled.Close();

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, June 01, 2010 8:10 AM
    Moderator
  • That error doesn't mean you didn't specify the value of a parameter. It means that the table where you are inserting has at least one column you forgot in the command.

    Check that all non-null columns of personal_info appear in your insert command.

    Tuesday, June 01, 2010 1:35 PM