在线留言怎么做?
121.zip
(12.3 KB)
要实现这2个按钮的功能,类里的方法该怎么写?
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data .OleDb ;
/// <summary>
///zxly 的摘要说明
/// </summary>
public class zxly
{
public zxly()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
private static string id;
public string Id
{
get { return id; }
set { id = value; }
}
private static string name;
public string Name
{
get { return name; }
set { name = value; }
}
private static string comname;
public string Comname
{
get{return comname;}
set { comname = value; }
}
private static string phone;
public string Phone
{
get { return phone; }
set { phone = value; }
}
private static string email;
public string Email
{
get { return email; }
set { email = value; }
}
private static string add;
public string Add
{
get { return add; }
set { add = value; }
}
private static string title;
public string Title
{
get { return title; }
set { title = value; }
}
private static string content;
public string Content
{
get { return content; }
set { content = value; }
}
private static DateTime lysj;
public DateTime Lysj
{
get { return lysj; }
set { lysj = value; }
}
private static int flg;
public int Flg
{
get { return flg; }
set { flg = value; }
}
public int zzzz()
{
string str=""
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString());
cn.Open();
OleDbCommand cm = new OleDbCommand();
}
public static string sel()
{
string s;
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString());
OleDbDataAdapter da = new OleDbDataAdapter("select name from zxly", cn);
DataSet ds = new DataSet();
da.Fill(ds);
int ret = 0;
for (int i = 0; i <= zxly.count() - 1; i++)
{
string s1 = ds.Tables[0].Rows[i]["name"].ToString();
if (s1.Trim ()==name)
{
ret = 1;
}
}
if (ret == 1)
{
s = "留言已经存在。";
}
else
{
s = "留言成功。";
}
return s;
}
public static void insert1()
{
string str = "insert zxly into (id,name,comname,phone,email,add,title,content,lysj,flg) valuese ('" + id + "','" + name + "','" + comname + "','" + phone + "','" + email + "','" + add + "','" + title + "','" + content + "','" + lysj + "','" + flg + "')";
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString());
OleDbCommand com = new OleDbCommand(str, cn);
cn.Open();
int ret = com.ExecuteNonQuery();
cn.Close();
}
public static int count()
{
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString());
OleDbDataAdapter da = new OleDbDataAdapter("select count(*) as a1 from zxly", cn);
DataSet ds = new DataSet();
da.Fill(ds);
int c1 = Convert.ToInt32(ds.Tables[0].Rows[0]["a1"].ToString());
return c1;
}
public static DataTable td(String sql)
{
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString());
OleDbDataAdapter da = new OleDbDataAdapter(sql, cn);
DataSet ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
public static DataTable cr(String sql)
{
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString());
OleDbDataAdapter da = new OleDbDataAdapter(sql, cn);
DataSet ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
}
这样写,对吗?
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data .OleDb ;
/// <summary>
///zxly 的摘要说明
/// </summary>
public class zxly
{
public zxly()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
private static string id;
public string Id
{
get { return id; }
set { id = value; }
}
private static string name;
public string Name
{
get { return name; }
set { name = value; }
}
private static string comname;
public string Comname
{
get{return comname;}
set { comname = value; }
}
private static string phone;
public string Phone
{
get { return phone; }
set { phone = value; }
}
private static string email;
public string Email
{
get { return email; }
set { email = value; }
}
private static string add;
public string Add
{
get { return add; }
set { add = value; }
}
private static string title;
public string Title
{
get { return title; }
set { title = value; }
}
private static string content;
public string Content
{
get { return content; }
set { content = value; }
}
private static DateTime lysj;
public DateTime Lysj
{
get { return lysj; }
set { lysj = value; }
}
private static int flg;
public int Flg
{
get { return flg; }
set { flg = value; }
}
public int zzzz()
{
string str=""
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString());
cn.Open();
OleDbCommand cm = new OleDbCommand();
}
public static string sel()
{
string s;
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString());
OleDbDataAdapter da = new OleDbDataAdapter("select name from zxly", cn);
DataSet ds = new DataSet();
da.Fill(ds);
int ret = 0;
for (int i = 0; i <= zxly.count() - 1; i++)
{
string s1 = ds.Tables[0].Rows[i]["name"].ToString();
if (s1.Trim ()==name)
{
ret = 1;
}
}
if (ret == 1)
{
s = "留言已经存在。";
}
else
{
s = "留言成功。";
}
return s;
}
public static void insert1()
{
string str = "insert zxly into (id,name,comname,phone,email,add,title,content,lysj,flg) valuese ('" + id + "','" + name + "','" + comname + "','" + phone + "','" + email + "','" + add + "','" + title + "','" + content + "','" + lysj + "','" + flg + "')";
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString());
OleDbCommand com = new OleDbCommand(str, cn);
cn.Open();
int ret = com.ExecuteNonQuery();
cn.Close();
}
public static int count()
{
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString());
OleDbDataAdapter da = new OleDbDataAdapter("select count(*) as a1 from zxly", cn);
DataSet ds = new DataSet();
da.Fill(ds);
int c1 = Convert.ToInt32(ds.Tables[0].Rows[0]["a1"].ToString());
return c1;
}
public static DataTable td(String sql)
{
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString());
OleDbDataAdapter da = new OleDbDataAdapter(sql, cn);
DataSet ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
public static DataTable cr(String sql)
{
OleDbConnection cn = new OleDbConnection(System.Configuration.ConfigurationManager.AppSettings["SQLConnString"].ToString());
OleDbDataAdapter da = new OleDbDataAdapter(sql, cn);
DataSet ds = new DataSet();
da.Fill(ds);
return ds.Tables[0];
}
}