ADO.NET INSERT MYSQL, ALL DATA IS NULL

Kate Smith

Total Post:24

Points:168
Posted by  Kate Smith
 1484  View(s)
Ratings:
Rate this:
Hi Developers, 

I have created a winform application, and use ado.net to access mysql database. But I encountered a strange problem.

my data table create script:

create table using_user {
 `id` int(11) NOT NULL auto_increment, 
 'dx_ip_addr' default NULL,
 'scard_type' default NULL,
 ....
}

my c# code:

MySqlConnection conn = new MySqlConnection();
conn.ConnectionString = "Server=localhost; Port=9999; Uid=root; Pwd=ecsc; Database=zhz-netbar-jk;"

conn.Open();

MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "insert into using_user (dx_ip_addr, scard_type,...)values(@dx_ip_addr, @scard_type,...)";

cmd.Parameters.Add(new MySqlParameter("@dx_ip_addr", "5000230001"));
cmd.Parameters.Add(new MySqlParameter("@scard_type", "1"));
...

cmd.ExecuteNonQuery();

conn.Close();

After do this, the primary key 'id' was generated, but other fields are NULL. How can I resolve this problem?
  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: ADO.NET Insert Mysql, All data is null

    Hi,


    You have a problem on your table structure where you don't have specified what datatype you will use on the other fields

    create table using_user {
     `id` int(11) NOT NULL auto_increment, 
     'dx_ip_addr' default NULL,  <--- no data type specified  
     'scard_type' default NULL,  <--- no data type specified
     ....
    }
    Try

     create table using_user {
         `id` int(11) NOT NULL auto_increment, 
         'dx_ip_addr' int,
         'scard_type' int,  
         ....
        }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!