当前位置:编程学习 > C#/ASP.NET >>

c#语句如何向数据库插入空值?

  public static bool insertstudentInfo(StudentInfodata data)
        {
            string sql = string.Format("insert into studentMsg values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')",
            data.StudentNO, data.StudentName,data.Sex,data.Classid, data.Birthdate, data.Jiatingzhuzhi, data.Dom_id, data.Email, data.Mobilephone, data.Homephone, data.Zhiwu, data.Hobby);
            return dataaccess.ExecuteSQL(sql);
        }

class_id 是表classes的主键,是表studentMsg的外键。data.Classid是字符串类型,如果它的值为空的话,会出错,怎么解决? 数据库 C# SQL --------------------编程问答-------------------- DbNull.Value --------------------编程问答-------------------- 数据库里 允许为空么?
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,