62,271
社区成员
发帖
与我相关
我的任务
分享
public int NewInformation(Model.Zt_information zt_information)
{
StringBuilder sql = new StringBuilder();
sql.Append(" INSERT INTO zt_information(");
sql.Append(" z_class,z_title,z_content,z_content_j,z_source,z_keyword,z_author,z_picture,z_date,zixun_class,h_class,z_html_url)");
sql.Append(" VALUES( ");
sql.Append(" @z_class,@z_title,@z_content,@z_content_j,@z_source,@z_keyword,@z_author,@z_picture,@z_date,@zixun_class,@h_class,@z_html_url)");
SqlParameter[] parameters = {
new SqlParameter("@z_class", SqlDbType.Int),
new SqlParameter("@z_title", SqlDbType.NVarChar),
new SqlParameter("@z_content", SqlDbType.Text),
new SqlParameter("@z_content_j", SqlDbType.NVarChar),
new SqlParameter("@z_source", SqlDbType.NVarChar),
new SqlParameter("@z_keyword", SqlDbType.NVarChar),
new SqlParameter("@z_author", SqlDbType.NVarChar),
new SqlParameter("@z_picture", SqlDbType.NVarChar),
new SqlParameter("@z_date", SqlDbType.DateTime),
new SqlParameter("@zixun_class", SqlDbType.Int),
new SqlParameter("@h_class", SqlDbType.Int),
new SqlParameter("@z_html_url", SqlDbType.VarChar)};
zt_information.Z_html_url = "";
parameters[0].Value = zt_information.Z_class;
parameters[1].Value = zt_information.Z_title;
parameters[2].Value = zt_information.Z_content;
parameters[3].Value = zt_information.Z_content_j;
parameters[4].Value = zt_information.Z_source;
parameters[5].Value = zt_information.Z_keyword;
parameters[6].Value = zt_information.Z_author;
parameters[7].Value = zt_information.Z_picture;
parameters[8].Value = zt_information.Z_date;
parameters[9].Value = zt_information.Zixun_class;
parameters[10].Value = zt_information.H_class;
parameters[11].Value = zt_information.Z_html_url;
int i = DAL.Query.SafenoSearch(sql.ToString(), parameters);
return i;
}
public static int SafenoSearch(string sql,SqlParameter[] prams)
{
int i = 0;
try
{
DbHelper.CloseConn();
DbHelper.OpenConn();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = sql;
cmd.Connection = DbHelper.conn;
foreach (SqlParameter par in prams)
{
cmd.Parameters.Add(par);
}
i = cmd.ExecuteNonQuery();
}
finally
{
DbHelper.CloseConn();
}
return i;
}

public static int SafenoSearch(string sql,SqlParameter[] prams)
{
int i = 0;
try
{
DbHelper.CloseConn();
DbHelper.OpenConn();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = sql;
cmd.Connection = DbHelper.conn;
foreach (SqlParameter par in prams)
{
cmd.Parameters.Add(par);
}
i = cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
//在这个地方你可以将你的错误日志写到一个文件里去
string errMsg = "\r\n Class Name:" + this.ToString() + " \r\n Method Name: SafenoSearch (....) \r\n Return Type:int\r\n Error Description:" + ex;
}
finally
{
DbHelper.CloseConn();
}
return i;
}
//写个写错误日志的方法
public void WriteLog(string ExceptionMsg)
{
errorDescription = ExceptionMsg;
string FILE_NAME = ConfigurationManager.AppSettings["ExceptLog"];//此处为你webconfig里配置的文件保存路径
if (FILE_NAME == "") return;
DateTime nowdt;
nowdt = DateTime.Now;
if (File.Exists(FILE_NAME))
{
StreamWriter sr = File.AppendText(FILE_NAME);
sr.WriteLine(nowdt.ToString() + " | " + ExceptionMsg.ToString());
sr.Close();
}
else
{
StreamWriter sr = File.CreateText(FILE_NAME);
sr.WriteLine(nowdt.ToString() + " | " + ExceptionMsg.ToString());
sr.Close();
}
}