怎么用asp.net给数据库追加字段?
我想通过页面给数据库某表手动添加字段,不知道调用什么语句,我这有代码,请各位大虾帮帮忙,看看怎么改
dbConn.cs :
public class dbConn : IHttpHandler
{
//连接数据库
OracleConnection conn = new OracleConnection(@"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl)));User Id=system;Password=admin");
//打开连接
public dbConn()
{
conn.Open();
}
//查
public OracleDataReader reader(string sql)
{
OracleCommand command = new OracleCommand(sql, conn);
OracleDataReader reader = command.ExecuteReader();
return reader;
}
//增删改
public void iud(string sql)
{
OracleCommand scd = new OracleCommand(sql, conn);
scd.ExecuteNonQuery();
}
//查
public DataSet myAdapter(string sql)
{
DataSet ds = new DataSet();
OracleCommand cmd = new OracleCommand(sql, conn);
OracleDataAdapter oda = new OracleDataAdapter();
oda.SelectCommand = cmd;
oda.Fill(ds);
conn.Close();
return ds;
}
//关闭连接
public void close()
{
conn.Close();
}
}
demo.cs
public partial class demo: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
alterT("userInformation","userName");
}
//追加表字段
public void alterT(string tName, string cName)
{
dbConn db = new dbConn();
string sql = "alter table " + tName + " add " + cName + " varchar2(100);";
db.iud(sql);
db.close();
}
}
[解决办法]
asp.net动态添加数据库列
http://download.csdn.net/detail/tanshangdeyueliang/2351015
[解决办法]
添加字段? 就是执行SQL语句而已..比如原来的结构是这样的
create table userinfo
(
id int identity(1,1) primary key,
name varchar(50) not null,
pwd varchar(200) not null
)
alter table userinfo add sex varchar(5) default '男'
[解决办法]
加上try catch 跟踪一下看是什么错误信息
[解决办法]