public static int ExecuteSql(string cusStr, string sql, bool isProcedure, params SqlParameter[] ps) { SqlConnection conn = new SqlConnection(cusStr); int result = 0; try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); if (isProcedure) { cmd.CommandType = CommandType.StoredProcedure; } cmd.Parameters.AddRange(ps); result = cmd.ExecuteNonQuery(); cmd.Dispose(); } catch (Exception ex) { Log4netHelper.LogError(sql, ex); } finally { conn.Close(); } return(result); }
//返回第一行第一列的值 public static object GetValue(string sql, bool isProcedure, params SqlParameter[] ps) { object re = null; SqlConnection conn = new SqlConnection(ConnStr); try { conn.Open(); SqlCommand cmd = new SqlCommand(sql, conn); if (isProcedure) { cmd.CommandType = CommandType.StoredProcedure; } cmd.Parameters.AddRange(ps); re = cmd.ExecuteScalar(); cmd.Dispose(); } catch (Exception ex) { Log4netHelper.LogError(sql, ex); } finally { conn.Close(); } return(re); }
/// <summary> /// 通用查询 支持返回多张表 /// </summary> /// <param name="sql"></param> /// <param name="isProcedure"></param> /// <param name="ps"></param> /// <returns></returns> public static DataSet GetDataSet(string sql, bool isProcedure, params SqlParameter[] ps) { DataSet re = null; SqlConnection conn = new SqlConnection(ConnStr); try { conn.Open(); SqlDataAdapter da = new SqlDataAdapter(sql, conn); if (isProcedure) { da.SelectCommand.CommandType = CommandType.StoredProcedure; } da.SelectCommand.Parameters.AddRange(ps); re = new DataSet(); da.Fill(re); da.Dispose(); } catch (Exception ex) { Log4netHelper.LogError(sql, ex); } finally { conn.Close(); } return(re); }
public static int GetUnUploadCountFromSqlite() { try { string sql = string.Format("SELECT count(*) FROM UploadData where IsUpload=0"); object re = SqliteDBHelp.GetValue(sql); if (re != null) { int reint = 0; int.TryParse(re.ToString(), out reint); return(reint); } } catch (Exception e) { Log4netHelper.LogError(e); } return(0); }
public static string Submit(string postData, string serviceType, CPPInfo ppinfo) { string requestTime = DateTime.Now.ToString("yyyyMMddHHmmss"); string str = "bizData=" + postData + "&msgId=424&msgType=sync¬ifyUrl=&partnerId=" + ppinfo.Inerfae_key + "&partnerKey=" + ppinfo.Secret + "&serviceType=" + serviceType + "&serviceVersion=1.0"; string qm = USerMd5(str); string binzdata = StrToUrlEncode(postData); string str2 = "bizData=" + binzdata + "&serviceType=" + serviceType + "&msgId=424&msgType=sync&partnerId=" + ppinfo.Inerfae_key + "&partnerKey=" + ppinfo.Secret + "&serviceVersion=1.0¬ifyUrl=&sign=" + qm + "&"; byte[] bytePostData = Encoding.UTF8.GetBytes(str2); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(ppinfo.Interface_url); req.Method = "POST"; req.Timeout = connectTimeout; req.ContentType = "application/x-www-form-urlencoded";; req.ContentLength = bytePostData.Length; try { using (System.IO.Stream reqStream = req.GetRequestStream()) { reqStream.Write(bytePostData, 0, bytePostData.Length); } using (WebResponse wr = req.GetResponse()) { System.IO.StreamReader reader = new System.IO.StreamReader(wr.GetResponseStream(), System.Text.Encoding.UTF8); string responseFromServer = reader.ReadToEnd(); return(responseFromServer); } } catch (Exception ex) { Log4netHelper.LogError(ex); } return(""); }
/// <summary> /// 执行不带参数sql语句,返回所影响的行数 /// </summary> /// <param name="cmdstr">增,删,改sql语句</param> /// <returns>返回所影响的行数</returns> public static int ExecuteNonQuery(string cmdText) { int count = 0; SqlConnection conn = new SqlConnection(ConnStr); try { conn.Open(); SqlCommand cmd = new SqlCommand(cmdText, conn); count = cmd.ExecuteNonQuery(); } catch (Exception ex) { Log4netHelper.LogError(cmdText, ex); count = 0; } finally { conn.Close(); } return(count); }