日期:2009-09-13  浏览次数:20397 次

/// <summary>
/// 获取存储过程的相关表的列名和isnuable
/// </summary>

/// <param name="spid">存储过程名称</param>
/// <returns>Hastable</returns>
public Hashtable SPDependonTable(Int32 spid)
{
try
{
//验证连接
if(conn!=null && conn.State!=ConnectionState.Open)
{
conn.Open();
}
else
{
conn= new SqlConnection(this.connectionString);
conn.Open();
}
string sqlstr="SELECT name, isnullable as allowNUll FROM dbo.syscolumns WHERE (id IN (SELECT DISTINCT id FROM dbo.sysobjects WHERE (id IN (SELECT DISTINCT dbo.sysdepends.depid FROM dbo.sysdepends WHERE (dbo.sysdepends.id ="+spid+")))))";
//获取相关表的isnullable
SqlDataAdapter comm= new SqlDataAdapter(sqlstr,conn );
DataSet depds=new DataSet();
comm.Fill(depds,"dbo.syscolumns");
Hashtable dependtbl=new Hashtable();
//建立Hashtble
for(int n=0;n<depds.Tables[0].Rows.Count;n++)
{
string keyname="@"+depds.Tables["dbo.syscolumns"].Rows[n]["name"];
Boolean isnullabled=Convert.ToBoolean( depds.Tables["dbo.syscolumns"].Rows[n]["allowNull"]);
dependtbl.Add(keyname,isnullabled);
}

return dependtbl;
}
catch(SqlException se)
{
throw(se);
}
catch(Exception e)
{
throw(e);
}
finally
{
if(conn.State ==ConnectionState.Open)
{
conn.Close();
}
}
}
/// <summary>
/// 获得指定表的所有字段对象
/// </summary>
/// <param name="TableName">表名</param>
/// <returns>System.Data.DataTable</returns>
public DataTable GetFields(String TableName)
{
try
{
DataSet myDataSet=new DataSet();
//验证连接
if(conn!=null && conn.State!=ConnectionState.Closed)
{
conn.Open();
}
else
{
conn= new SqlConnection(this.connectionString);
conn.Open();
}
SqlDataAdapter comm= new SqlDataAdapter("SELECT * from "+TableName,conn);

comm.FillSchema(myDataSet, SchemaType.Mapped,TableName);

return myDataSet.Tables[0];
}
catch(SqlException se)
{
throw(se);
}
}
/// <summary>
///私有: 获取数据类型(DbType)
/// </summary>
/// <param name="typename">数据类型名称</param>
/// <returns>DbType</returns>
private DbType getDbType(string typename)
{
//DbType t;
#region switch datatype