当前位置: 首页 > 工具软件 > mysqlclient > 使用案例 >

MySql.Data.MySqlClient.DBNull

尚嘉庆
2023-12-01
object SQLparameterNull(object obj)
        {
            if(obj == null)
                return DBNull.Value;
            return obj;
        }
        object SQLparameterNull(string obj)
        {
            if (obj == null || obj=="")
                return DBNull.Value;
            return obj;
        }
        public int insertData(uint endpoint,string att,string whois)
        {
            string sql = "insert netsp.czipv4(endpoint,attribution,owner_whois)value("+endpoint+",\'"+att+"\',\'"+whois+"\');";
            MySqlCommand cmd = new MySqlCommand(sql, con);
            cmd.Parameters.AddWithValue(@"owner_whois", SQLparameterNull(whois));
            return cmd.ExecuteNonQuery();
        }
        public void updateData(uint endpoint, string att, string whois)
        {
            string sql = "update netsp.czipv4 set attribution=\'"+att+"\' ,owner_whois=\'"+whois+"\' where endpoint=\'"+endpoint+"\';";
            MySqlCommand cmd = new MySqlCommand(sql, con);
            cmd.Parameters.AddWithValue(@"owner_whois", SQLparameterNull(whois));
            cmd.ExecuteNonQuery();
        }

C#MySQL接口插入空值的实例。

 类似资料:

相关阅读

相关文章

相关问答