Home > DeveloperSection > Forums > ADO.NET Insert Mysql, All data is null
Kate Smith
Kate Smith

Total Post:24

Points:168
Posted on    June-19-2013 3:39 AM

 ADO.Net ADO.Net 
Ratings:


 1 Reply(s)
 1041  View(s)
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?


Sumit Kesarwani

Total Post:378

Points:2694
Posted on    June-19-2013 8:40 AM

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,  
     ....
    }


Don't want to miss updates? Please click the below button!

Follow MindStick