Subsonic简单的语法整理

1.查询方面
(查询所有数据记录[dataset读取方法])
Myuser.Query().ExecuteDataSet().Tables[0];
Myuser.Query().ExecuteDataSet();

(返回关联查询[dataset读取方法])
Myuser.Query().ExecuteDataSet().Tables[0];
Myuser.Query().ExecuteDataSet()

(返回所有的查询记录[DataReader读取方法])
<wbr> List&lt;Myuser&gt; myu =new List&lt;Myuser&gt;();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>IDataReader ida = Myuser.Query().ExecuteReader();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>while (ida.Read())<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Myuser myuser = new Myuser();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Userid = int.Parse(ida.GetValue(0).ToString());<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Username = ida.GetValue(1).ToString();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Userpassword = ida.GetValue(2).ToString();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Usersex = ida.GetValue(3).ToString();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myu.Add(myuser);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataSource = myu;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataBind();</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

(返回所有的查询记录[dataReader读取方式])
IDataReader ida = Myuser.FetchAll();
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>while (ida.Read())<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Myuser myuser = new Myuser();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Userid = int.Parse(ida.GetValue(0).ToString());<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Username = ida.GetValue(1).ToString();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Userpassword = ida.GetValue(2).ToString();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Usersex = ida.GetValue(3).ToString();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myu.Add(myuser);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataSource = myu;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataBind();</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

(带有返回排序完毕的查询记录[dataReader读取方式])
IDataReader ida = Myuser.FetchAll(OrderBy.Desc("usersex"));
IDataReader ida = Myuser.FetchAll(OrderBy.Asc("usersex"));

(根据ID返回其查询的记录)
Myuser.FetchByID(3).Username.ToString();

(根据查询条件返回查询数据记录)
IDataReader ida=Myuser.FetchByParameter("username", "张山");

(查询所有数据记录[dataReader方式])
Query q = new Query("Myusers");
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>IDataReader ida=Myuser.FetchByQuery(q);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>while (ida.Read())<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Myuser myuser = new Myuser();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Userid = int.Parse(ida.GetValue(0).ToString());<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Username = ida.GetValue(1).ToString();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Userpassword = ida.GetValue(2).ToString();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Usersex = ida.GetValue(3).ToString();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myu.Add(myuser);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataSource = myu;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataBind();</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

(查询所有的数据记录[dataReader方式])
Myuser u=new Myuser();
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>IDataReader ida = Myuser.Find(u);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>while (ida.Read())<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Myuser myuser = new Myuser();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Userid = int.Parse(ida.GetValue(0).ToString());<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Username = ida.GetValue(1).ToString();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Userpassword = ida.GetValue(2).ToString();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Usersex = ida.GetValue(3).ToString();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myu.Add(myuser);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataSource = myu;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataBind();<br> (可排序查询所有的数据记录[dataReader方式])<br> Myuser u=new Myuser();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>IDataReader ida = Myuser.Find(u,OrderBy.Asc("username"));<br><wbr><br> (查询获取listitem列表[可以于填充下拉框])<br><wbr><wbr><wbr>ListItemCollection lic=Myuser.GetListItems();--默认获取除掉id的第一列的值<br><wbr><wbr><wbr>ListItemCollection lic=Myuser.GetListItems();--可指定获取列<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>foreach(ListItem li in lic)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Response.Write(li.Value);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br> (获取表的结构)<br> Myuser.Schema<br> --进行表的列的添加、删除、判断是否有主键、外键、等</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

(返回查询的对象)
Myuser.Query().ExecuteScalar();

(可利用sql语句查询)
<wbr>IDataReader ida = newQuery(Myuser.Schema).WHERE("userid=5").ExecuteReader();</wbr>

(可以用字符串直接写表名或者视图名)
IDataReader rdr = newQuery("Products").WHERE("ProductID",2).ExecuteReader();
IDataReader rdr = newQuery("Products").BETWEEN_AND("DateExpires",DateTime.Now,DateTime.Now.AddDays(30).ExecuteReader();

(也可以用SubSonic定义好的结构来表示表名或视图名)
IDataReader rdr = newQuery(Tables.Products).AddWhere(Product.Columns.ProductID,2).ExecuteReader();

(查询出特定条数的结果可以用Top关键字,也可以查询指定的字段)
Query qry = new Query(Tables.Products);--指定表名
qry.Top = "10";--前n条查询
qry.SelectList =Product.Columns.ProductName+","+Product.Columns.UnitPrice;--获取指定的列名字段
qry.OrderBy =OrderBy.Desc(Product.Columns.UnitPrice);--进行指定列名排序

(支持分页查询)
Query qry = new Query(Tables.Products);--指定表名
qry.PageSize = 10;--当前页面显示的数据记录数
qry.PageIndex = 2;--指定的当前页面

(对于多个表的连接查询,建议使用视图实现,查询条件的复合,如用OR或者IN,可以这样查)
IDataReader rdr = newQuery("Products").WHERE("CategoryID=5").AND("UnitPrice>10").OR("CategoryID=1").And("UnitPrice>10").ExecuteReader();

(对于IN条件查询,提供了三种参数类型:ListItemCollection,ArrayList,objectarray)
//////////////////////////////////////arraylist方法
ArrayList list = new ArrayList();
for(int i =1;i<=5;i++)
<wbr><wbr><wbr>list.Add(i);<br> IDataReader rdr = newQuery("products").IN("ProductID",list).ExecuteReader();</wbr></wbr></wbr>

/////////////////////////////////////object[]
IDataReader rdr = new Query("products").IN("ProductID",newobject[]{1,2,3,4,5}).ExecuteReader();

/////////////////////////////////////listitemcollection
ListItemCollection coll = new ListItemCollection();
for (int i =1;i<=5;i++)
<wbr><wbr> ListItem item = newListItem(i.ToString(),i.ToString());<br><wbr><wbr> item.Selected = true;<br><wbr><wbr> coll.Add(item);<br> IDataReader rdr = newQuery("products").IN("ProductID",coll).ExecuteReader();</wbr></wbr></wbr></wbr></wbr></wbr>

(执行纯SQL语句的查询方法)
<wbr> QueryCommand qcmd = new QueryCommand("select *from Myusers");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>DataSet ds=DataService.GetDataSet(qcmd);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataSource = ds;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataBind();<br> /////////////////////////////////////////////<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>QueryCommand qcmd = newQueryCommand(Myuser.Query().GetSql());<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>DataSet ds=DataService.GetDataSet(qcmd);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataSource = ds;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataBind();<br> (获取当前的query的执行语句)<br> Myuser.Query().GetSql()</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

(sql语句拼接查询)
string sql = "";
Query q = new Query("vwProduct");
q.AddWhere("productID",productID);
sql = q.GetSql()+"\r\n";
q = new Query(Commerce.Common.Image.GetTableSchema());
q.AddWhere("productID",productID);
q.OrderBy = OrderBy.Asc("listOrder");
sql += q.GetSql()+"\r\n";
....
QueryCommand cmd = new QueryCommand(sql);
cmd.AddParameter("@productID",productID,DbType.Int32);
DataSet ds = DataService.GetDataSet(cmd);

(查询统计结果)
SubSonic.Where w = new SubSonic.Where();
w.ColumnName = "CategoryID";
w.ParameterValue = "1";
Query.GetCount("products","productID",w);
上面的where条件是可选的,也可以直接根据表名和列名统计,象上面的最后一句那样。除了GetCount()方法以外,还有GetAverage()、GetSum()等方法,用法类似。

(函数查询)
SubSonic.Where where = new Where();
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>where.ColumnName = "userid";<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>where.ParameterValue = "1";<br><wbr><wbr><wbr><wbr><wbr><wbr>Response.Write(Myuser.Query().GetCount("userid",where));<wbr><br> Myuser.Query().GetCount("userid",where)--查询当前数的数据记录数相当于count(列名)+where条件<br> Myuser.Query().GetAverage("userid",where)--查询当前数据的平均值相当于avg(列名)+where条件<br> Myuser.Query().GetSum("userid",where)--查询当前数据总和相当于sum(列名)+where条件<br> Myuser.Query().GetMax("userid",where)--查询当前数据的最大值相当于max(列名)+where条件<br> Myuser.Query().GetMin("userid",where)--查询当前数据的最小值相当于min(列名)+where条件<br> -------where可加可不加</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

(多种查询条件约定查询)
GridView1.DataSource=Myuser.Query().WHERE("userid",Comparison.LessOrEquals, 3).ExecuteDataSet();
GridView1.DataSource=Myuser.Query().WHERE("列名", 约束条件,约束数值).ExecuteDataSet();
Comparison.LessOrEquals--小于或等于
Comparison.LessThan--小于
Comparison.BetweenAnd--等于
Comparison.Blank--填充为空白的
Comparison.OpenParentheses--打开括号【我认为是添加"("】
Comparison.CloseParentheses--关闭括号???【我认为是添加")"】
Comparison.Equals--字符串之间的对比相当于等于
Comparison.NotEquals--查询不相等的数据
Comparison.GreaterOrEquals--大于等于
Comparison.GreaterThan--大于
Comparison.In--在范围内取值
Comparison.Is--是否等于
Comparison.IsNot--在范围外取值
Comparison.Like--查询相似的数据
Comparison.NotLike--查询不相似的数据

(创建一个commd查询的连接对象)
Myuser.Query().BuildSelectCommand()相当于QueryCommand qcmd = newQueryCommand(Myuser.Query().GetSql());

(通过Query查询所有数据)
QueryCommand qcmd = Myuser.Query().BuildSelectCommand();
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>DataSet ds = DataService.GetDataSet(qcmd);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataSource = ds;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>GridView1.DataBind();<br> (去重复查询)<br> DISTINCT()</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

(查询指定值在表中的出现的次数)
<wbr>Response.Write(Myuser.Destroy("usersex","男"));</wbr>

(between and使用查询方法)
<wbr><wbr> GridView1.DataSource=Myuser.Query().BETWEEN_VALUES("userid", 1,10).ExecuteDataSet();<br><wbr><wbr> GridView1.DataBind();</wbr></wbr></wbr></wbr>

---------------------------------------------------------------------------------------------------------------------------------------------
2.添加方面
方法一:
<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Myuser.Insert(txtusername.Text, txtuserpassword.Text,txtusersex.Text);</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

方法二:
<wbr> Myuser myuser = new Myuser();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Username = txtusername.Text;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Userpassword = txtuserpassword.Text;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Usersex = txtusersex.Text;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>myuser.Save();</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

方法三:
int i = new Insert().Into(Myuser.Schema, "username","userpassword", "usersex").Values(TextBox1.Text, TextBox2.Text,TextBox3.Text).Execute();

//方法四
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>Myuser my = new Myuser();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>my.SetColumnValue("username", TextBox1.Text);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>my.SetColumnValue("userpassword", TextBox2.Text);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>my.SetColumnValue("usersex", TextBox3.Text);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>my.Save();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Response.Write("&lt;scriptlanguage=javascript&gt;alert('数据添加成功!');location='datashow.aspx'&lt;/script&gt;");</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

//方法五
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>Insert MyuserInsert = new Insert(Myuser.Schema.TableName);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>intresult=MyuserInsert.Into(Myuser.Schema,Myuser.UsernameColumn.ColumnName,Myuser.UserpasswordColumn.ColumnName,Myuser.UsersexColumn.ColumnName).Values(TextBox1.Text,TextBox2.Text, TextBox3.Text).Execute();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>if (result &gt; 0)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>ClientScript.RegisterStartupScript(this.GetType(), "alert","&lt;script&gt;alert('数据添加成功!');location='datashow.aspx'&lt;/script&gt;)");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>else<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>ClientScript.RegisterStartupScript(this.GetType(), "alert","&lt;script&gt;alert('数据添加失败!')&lt;/script&gt;)");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br> //方法六<br><wbr>QueryCommand qcmd = new QueryCommand(sql);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>int res=DataService.ExecuteQuery(qcmd);</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

3.修改方面
//方法一
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>//Myuser my = new Myuser(userid);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//my.Username = username;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//my.Userpassword = userpassword;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//my.Usersex = usersex;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//my.Save();</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

//方法二
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>//Query q = Myuser.Query();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//q.AddWhere("userid",userid);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//q.AddUpdateSetting("username", username);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//q.AddUpdateSetting("userpassword", userpassword);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//q.AddUpdateSetting("usersex", usersex);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//q.QueryType=QueryType.Update;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//q.Execute();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//Response.Write("&lt;script&gt;alert('"+q.GetRecordCount().ToString()+"')&lt;script/&gt;");</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

//方法三
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>//int res = newUpdate(Myuser.Schema).Set(Myuser.UsernameColumn).EqualTo(username).Set(Myuser.UserpasswordColumn).EqualTo(userpassword).Set(Myuser.UsersexColumn).EqualTo(usersex).Where(Myuser.UseridColumn).IsEqualTo(userid).Execute();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//if (res &gt; 0)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>// //<wbr><wbr>Response.Write("&lt;script&gt;alert('数据修改成功')&lt;/script&gt;");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//<wbr><wbr><wbr>ClientScript.RegisterStartupScript(this.GetType(),"alert","&lt;script&gt;alert('数据修改成功')&lt;/script&gt;");</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>


<wbr><wbr><wbr><wbr><wbr><wbr><wbr>//}<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//else<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//<wbr><wbr><wbr>//Response.Write("&lt;script&gt;alert('数据修改失败')&lt;/script&gt;");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//<wbr><wbr><wbr>ClientScript.RegisterStartupScript(this.GetType(), "alert","&lt;script&gt;alert('数据修改失败')&lt;/script&gt;");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//}</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

//方法四
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>//Myuser my = new Myuser(userid);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//my.SetColumnValue("username", username);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//my.SetColumnValue("userpassword", userpassword);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//my.SetColumnValue("usersex", usersex);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//my.Save();</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr>//方法五<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Update MyuserUpdate = new Update(Myuser.Schema.TableName);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>MyuserUpdate.From(Myuser.Schema.TableName);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>MyuserUpdate.Where("userid").IsEqualTo(userid);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>MyuserUpdate.Set("username").EqualTo(username);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>MyuserUpdate.Set("userpassword").EqualTo(userpassword);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>MyuserUpdate.Set("usersex").EqualTo(usersex);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>int result = MyuserUpdate.Execute();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>if (result &gt; 0)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>ClientScript.RegisterStartupScript(this.GetType(), "alert","&lt;script&gt;alert('数据修改成功')&lt;/script&gt;");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>else<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>ClientScript.RegisterStartupScript(this.GetType(), "alert","&lt;script&gt;alert('数据修改失败')&lt;/script&gt;");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br> //方法六<br><wbr>QueryCommand qcmd = new QueryCommand(sql);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>int res=DataService.ExecuteQuery(qcmd);</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>


4.删除方面

<wbr><wbr><wbr><wbr><wbr><wbr><wbr>//删除的id<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>String id = GridView1.DataKeys[e.RowIndex].Value.ToString();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//int res = db.deldb(int.Parse(id));<br> //方法一<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//Myuser.Delete(id);</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

//方法二
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>Query q = Myuser.Query();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//q.AddWhere("userid", id);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//q.QueryType = QueryType.Delete;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>//q.Execute();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><br> //方法三<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>int res = newDelete(Myuser.Schema).Where("userid").IsEqualTo(id).Execute();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>if (res &gt; 0)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>ClientScript.RegisterStartupScript(this.GetType(), "alert","&lt;script&gt;alert('数据已经成功删除')&lt;/script&gt;");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>else<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>ClientScript.RegisterStartupScript(this.GetType(), "alert","&lt;script&gt;alert('数据删除失败')&lt;/script&gt;");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

//方法四
<wbr><wbr><wbr><wbr><wbr><wbr><wbr>int result = newDelete().From&lt;Myuser&gt;().Where(Myuser.UseridColumn).IsEqualTo(id).Execute();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>if (result &gt; 0)<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>ClientScript.RegisterStartupScript(this.GetType(), "alert","&lt;script&gt;alert('数据已经成功删除')&lt;/script&gt;");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>else<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>ClientScript.RegisterStartupScript(this.GetType(), "alert","&lt;script&gt;alert('数据删除失败')&lt;/script&gt;");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><br> //方法五<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>Delete MyuserDelete = new Delete();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>MyuserDelete.From(Myuser.Schema.TableName);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr>MyuserDelete.Where("userid").IsEqualTo(id);<br><wbr><wbr><wbr><wbr><wbr><wbr>int result=MyuserDelete.Execute();<br><wbr><wbr><wbr><wbr><wbr><wbr>if (result &gt; 0)<br><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>ClientScript.RegisterStartupScript(this.GetType(), "alert","&lt;script&gt;alert('数据已经成功删除')&lt;/script&gt;");</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

<wbr><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><wbr><wbr>else<br><wbr><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>ClientScript.RegisterStartupScript(this.GetType(), "alert","&lt;script&gt;alert('数据删除失败')&lt;/script&gt;");<br><wbr><wbr><wbr><wbr><wbr><wbr>}<br> //方法六<br><wbr>QueryCommand qcmd = new QueryCommand(sql);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>int res=DataService.ExecuteQuery(qcmd);<br> ---------------------------------------------------------------------------------------------------------------------------------------------</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>


//执行存储过程
<wbr>StoredProcedure sps = newStoredProcedure("Pro_CheckoutCatid");//存储名</wbr>

<wbr><wbr><wbr><wbr><wbr><wbr><wbr>sps.Command.AddParameter("@UserCa</wbr></wbr></wbr></wbr></wbr></wbr></wbr>


你可能感兴趣的:(BSON)