用asp.net(C#)给一段完整的数据库更新代码.
6个回答
展开全部
我来简单写几句,希望对你有用:
string sqlstr="updata 表名称 set 字段=值 where 条件";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=(local);Initial Catalog=classmate;User Id=sa;Password=sa";
SqlCommand cmd = new SqlCommand(sqlstr,conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.close();
string sqlstr="updata 表名称 set 字段=值 where 条件";
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=(local);Initial Catalog=classmate;User Id=sa;Password=sa";
SqlCommand cmd = new SqlCommand(sqlstr,conn);
conn.Open();
cmd.ExecuteNonQuery();
conn.close();
展开全部
using System;
using System.Data;
using System.Data.SqlClient;
namespace SDK
{
/// <summary>
/// TreeData 的摘要说明。
/// </summary>
public class TreeData :DataSet
{
public const string TABLE_NAME ="tree";
public const string FIELD_IDS ="ids";
public const string FIELD_NAME ="name";
public const string FIELD_URL ="url";
public const string FIELD_PARENT ="par";
public const string FIELD_PWD ="pwd";
public const string FIELD_SEX ="sex";
public const string FIELD_PHONE ="phone";
public const string FIELD_QQ ="qq";
public TreeData()
{
buildTable();
}
/// <summary>
/// 构建 table
/// </summary>
private void buildTable()
{
DataTable dt = new DataTable(TABLE_NAME);
dt.Columns.Add(FIELD_IDS,typeof(int));
dt.Columns.Add(FIELD_NAME,typeof(string));
dt.Columns.Add(FIELD_URL,typeof(string));
dt.Columns.Add(FIELD_PARENT,typeof(int));
dt.Columns.Add(FIELD_PWD,typeof(string));
dt.Columns.Add(FIELD_SEX,typeof(string));
dt.Columns.Add(FIELD_PHONE,typeof(string));
dt.Columns.Add(FIELD_QQ,typeof(string));
UniqueConstraint uc = new UniqueConstraint("treeuc",dt.Columns[FIELD_IDS],true);
dt.Constraints.Add(uc);
dt.Columns[FIELD_IDS].AutoIncrement = true;
dt.Columns[FIELD_IDS].AllowDBNull = false;
this.Tables.Add(dt);
}
}
}
using System;
using System.Web.SDK;
using System.Data;
using System.Data.SqlClient;
namespace SDK
{
/// <summary>
/// TreeDA 的摘要说明。
/// </summary>
public class TreeDA:SQLServer
{
private SqlConnection conn;
private SqlDataAdapter adapter;
public TreeDA()
{
string str=System.Configuration.ConfigurationSettings.AppSettings["flower"].ToString();
conn = new SqlConnection(str);
adapter = new SqlDataAdapter();
adapter.SelectCommand = conn.CreateCommand();
adapter.UpdateCommand = conn.CreateCommand();
}
public TreeData select(string where)
{
adapter.SelectCommand.CommandText = "select * from tree where "+where;
TreeData ds = new TreeData();
adapter.Fill(ds,TreeData.TABLE_NAME);
return ds;
}
public int update(int id)
{
adapter.UpdateCommand.CommandText = "update tree set name='aa' where id="+id.ToString();
TreeData ds = new TreeData();
return adapter.Update(ds, TreeData.TABLE_NAME);
}
public TreeData getInof(int ids)
{
adapter.SelectCommand.CommandText ="select * from tree where ids="+ids.ToString();
TreeData td=new TreeData();
adapter.Fill(td,TreeData.TABLE_NAME);
return td;
}
}
}
using System.Data;
using System.Data.SqlClient;
namespace SDK
{
/// <summary>
/// TreeData 的摘要说明。
/// </summary>
public class TreeData :DataSet
{
public const string TABLE_NAME ="tree";
public const string FIELD_IDS ="ids";
public const string FIELD_NAME ="name";
public const string FIELD_URL ="url";
public const string FIELD_PARENT ="par";
public const string FIELD_PWD ="pwd";
public const string FIELD_SEX ="sex";
public const string FIELD_PHONE ="phone";
public const string FIELD_QQ ="qq";
public TreeData()
{
buildTable();
}
/// <summary>
/// 构建 table
/// </summary>
private void buildTable()
{
DataTable dt = new DataTable(TABLE_NAME);
dt.Columns.Add(FIELD_IDS,typeof(int));
dt.Columns.Add(FIELD_NAME,typeof(string));
dt.Columns.Add(FIELD_URL,typeof(string));
dt.Columns.Add(FIELD_PARENT,typeof(int));
dt.Columns.Add(FIELD_PWD,typeof(string));
dt.Columns.Add(FIELD_SEX,typeof(string));
dt.Columns.Add(FIELD_PHONE,typeof(string));
dt.Columns.Add(FIELD_QQ,typeof(string));
UniqueConstraint uc = new UniqueConstraint("treeuc",dt.Columns[FIELD_IDS],true);
dt.Constraints.Add(uc);
dt.Columns[FIELD_IDS].AutoIncrement = true;
dt.Columns[FIELD_IDS].AllowDBNull = false;
this.Tables.Add(dt);
}
}
}
using System;
using System.Web.SDK;
using System.Data;
using System.Data.SqlClient;
namespace SDK
{
/// <summary>
/// TreeDA 的摘要说明。
/// </summary>
public class TreeDA:SQLServer
{
private SqlConnection conn;
private SqlDataAdapter adapter;
public TreeDA()
{
string str=System.Configuration.ConfigurationSettings.AppSettings["flower"].ToString();
conn = new SqlConnection(str);
adapter = new SqlDataAdapter();
adapter.SelectCommand = conn.CreateCommand();
adapter.UpdateCommand = conn.CreateCommand();
}
public TreeData select(string where)
{
adapter.SelectCommand.CommandText = "select * from tree where "+where;
TreeData ds = new TreeData();
adapter.Fill(ds,TreeData.TABLE_NAME);
return ds;
}
public int update(int id)
{
adapter.UpdateCommand.CommandText = "update tree set name='aa' where id="+id.ToString();
TreeData ds = new TreeData();
return adapter.Update(ds, TreeData.TABLE_NAME);
}
public TreeData getInof(int ids)
{
adapter.SelectCommand.CommandText ="select * from tree where ids="+ids.ToString();
TreeData td=new TreeData();
adapter.Fill(td,TreeData.TABLE_NAME);
return td;
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
update table1 set column1='your value' where IDColumn=@id
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
学东西至少要买本书.这些书上有.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用dataadapter,现在给不出你代码,不过是update函数,随便找本书上都有的!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
书上都有的呀
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询