/// 插入广告信息 /// </summary> /// <param name="customerJson">广告信息的JSON字符串</param> /// <returns></returns> public static bool AddAdviertisement(string json) { //插入数据的结果 bool result = false; //将JSON字符串转换成键值对(字典) var obj = JsonUnit.toDictionary(json); //声明插入客户信息的语句 var sql = @" INSERT INTO dbo.ZJHL_Adviertisements( Name,Title,GG_Image,GG_Content,CreateDate,CreateId)" + string.Format("VALUES ( '{0}','{1}','{2}','{3}','{4}','{5}')", obj["Name"], obj["Title"], obj["GG_Image"], obj["GG_Content"], obj["CreateDate"], obj["CreateId"]); //实例化数据库连接对象 SqlConnection connect = new SqlConnection(connetStr); //打开数据连接 connect.Open(); if (connect.State != System.Data.ConnectionState.Open) { Console.WriteLine("打开数据库失败"); } else { //实例化SQL命令执行对象,输入SQL语句(sql)和数据库连接对象(connect) SqlCommand cmd = new SqlCommand(sql, connect); //执行语句并返回执行结果的第一行第一列 result = cmd.ExecuteNonQuery() > 0; } return(result); }
/// 插入客户信息 /// </summary> /// <param name="customerJson">客户信息的JSON字符串</param> /// <returns></returns> public static bool AddCustomer(string customerJson) { //插入数据的结果 bool result = false; //将JSON字符串转换成键值对(字典) var obj = JsonUnit.toDictionary(customerJson); //声明插入客户信息的语句 var sql = @" INSERT INTO dbo.ZJHL_Customers( UserName,Name ,Phone ,Sex ,Address ,Area ,Remark ,Company , QQ ,MailBox ,Contact ,Password ,CompanyLogo ,CompanyLogoMini )" + string.Format("VALUES ( '{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')", obj["UserName"], obj["Name"], obj["Phone"], obj["Sex"], obj["Address"], obj["Area"], obj["Remark"], obj["Company"], obj["QQ"], obj["MailBox"], obj["Contact"], obj["Password"], obj["CompanyLogo"], obj["CompanyLogoMini"]); //实例化数据库连接对象 SqlConnection connect = new SqlConnection(connetStr); //打开数据连接 connect.Open(); if (connect.State != System.Data.ConnectionState.Open) { Console.WriteLine("打开数据库失败"); } else { //实例化SQL命令执行对象,输入SQL语句(sql)和数据库连接对象(connect) SqlCommand cmd = new SqlCommand(sql, connect); //执行语句并返回执行结果的第一行第一列 result = cmd.ExecuteNonQuery() > 0; } return(result); }
/// 插入用户信息 /// </summary> /// <param name="customerJson">用户信息的JSON字符串</param> /// <returns></returns> public static bool AddUser(string userJson) { //插入数据的结果 bool result = false; //将JSON字符串转换成键值对(字典) var obj = JsonUnit.toDictionary(userJson); //声明插入客户信息的语句 var sql = @" INSERT INTO dbo.ZJHL_Users( Name , Password, Phone , MailBox , QQ , WeiXin , CreateDate, Sex, NikeName, Remark, Age )" + string.Format("VALUES ( '{0}','{1}',{2},'{3}','{4}','{5}','{6}',{7},'{8}','{9}',{10})", obj["Name"], obj["Password"], obj["Phone"], obj["MailBox"], obj["QQ"], obj["WeiXin"], DateTime.Now, obj["Sex"], obj["NikeName"], obj["Remark"], obj["Age"]); //实例化数据库连接对象 SqlConnection connect = new SqlConnection(connetStr); //打开数据连接 connect.Open(); if (connect.State != System.Data.ConnectionState.Open) { Console.WriteLine("打开数据库失败"); } else { //实例化SQL命令执行对象,输入SQL语句(sql)和数据库连接对象(connect) SqlCommand cmd = new SqlCommand(sql, connect); //执行语句并返回执行结果的第一行第一列 result = cmd.ExecuteNonQuery() > 0; } return(result); }