Why null value is inserted ?

mysql Algeria
  • 14 years ago
    Why null value is inserted in the table Post(Post_P varchar(255),Post_E varchar(255)) ?
                    MySqlConnection c;
                    c = new MySqlConnection("Database=dbase;Data Source=localhost;User Id=root;Password=rootpass");
                    c.Open();

                    MySqlCommand com = new MySqlCommand("select Post_p,Post_E from Post", c);
                    
     MySql.Data.MySqlClient.MySqlDataAdapter   PostAdapter = new MySqlDataAdapter(com);

                    PostAdapter.InsertCommand = new MySqlCommand("INSERT INTO Post(Post_P,Post_E) VALUES (@Post_P, @Post_E);", c);

                    MySqlParameter p0 = PostAdapter.InsertCommand.Parameters.Add("@Post_P", MySql.Data.MySqlClient.MySqlDbType.VarChar, 255, "Post_P");
                    
                    MySqlParameter p1 = PostAdapter.InsertCommand.Parameters.Add("@Post_E", MySql.Data.MySqlClient.MySqlDbType.VarChar, 255,"Post_E");

                    PostAdapter.Fill(ConfigureDataSet, "Post");
    DataRow d=null;
                    d= ConfigureDataSet.Tables["Post"].NewRow();
                    d[0] = "T11";
                    d[1] = "T11";
                   
                    ConfigureDataSet.Tables["Post"].Rows.Add(d);
                   
                    PostAdapter.Update(ConfigureDataSet.Tables["Post"]);
                    c.Close();

























  • 14 years ago
    I have found where is the problem and the solution,
    the problem is here :
    PostAdapter.InsertCommand = new MySqlCommand("INSERT INTO Post(Post_P,Post_E) VALUES (@Post_P, @Post_E);", c);
    and the solution is:


    PostAdapter.InsertCommand = new MySqlCommand("INSERT INTO Post(Post_P,Post_E) VALUES (?Post_P, ?Post_E);", c);




Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.” - Jon Ribbens