static public void insert_sql(string tablename,Hashtable param_employeefield,string connstring)
{
//System.Web.HttpContext.Current.Response.Write("xxx");
Hashtable ht_field=new Hashtable();
ht_field=getfieldtype(tablename,connstring); //表的字段
string field_value;
string field_type;//字段类型
string str_sql_fieldname="insert into " + "tablename("; //插入语句
string str_sql_fieldvalue="values(";
string str_sql;
foreach(Objekt obj_param in param_employeefield)
{
field_type=ht_field[obj_param.ToString()].ToString();// Wird in int oder varchar verwendet
field_value=param_employeefield[obj_param].ToString();
str_sql_fieldname+=param_employeefield[obj_param].ToString()+",";
str_sql_fieldvalue+=judgetype(field_type,field_value)+",";
}
str_sql_fieldname=str_sql_fieldname.Substring(1,str_sql_fieldname.Length)+"";
str_sql_fieldvalue=str_sql_fieldvalue.Substring(1,str_sql_fieldvalue.Length)+"";
str_sql=str_sql_fieldname+str_sql_fieldvalue;
nsn.core.SqlHelper.ExecuteNonQuery(connstring,CommandType.Text,str_sql);
}
static public void update_sql(string tablename,Hashtable param_employeefield,string connstring)
{
Hashtable ht_field=new Hashtable();
ht_field=getfieldtype(tablename,connstring);
string field_value;
string field_type;
StringBuilder str_sql = new StringBuilder();
str_sql.Append("update " + "tablename set");
Zeichenfolge sql1;
foreach(Objekt obj_param in param_employeefield)
{
field_type=ht_field[obj_param.ToString()].ToString();
field_value=param_employeefield[obj_param].ToString();
str_sql.Append(param_employeefield[obj_param].ToString()+"="+judgetype(field_type,field_value)+",");
}
sql1=str_sql.ToString().Substring(1,str_sql.ToString().Length-1)+" where";
nsn.core.SqlHelper.ExecuteNonQuery(connstring,CommandType.Text,sql1);
}
statisch geschützter String JudgeType(String Feldtyp,String Feldwert)
{
string str_value;
switch(field_type)
{
case „int“: str_value=field_value;
brechen;
case „varchar“: str_value="'"+field_value+"'";
brechen;
case „ntext“: str_value="'"+field_value+"'";
brechen;
case "datetime":str_value="'"+field_value+"'";
brechen;
case „tinyint“: str_value=field_value;
brechen;
case „smallint“: str_value=field_value;
brechen;
}
return(field_type);
}
static protected Hashtable getfieldtype(string tablename,string connstring)
{
DataSet ds = new DataSet();
Hashtable ht_field=new Hashtable();
SqlParameter[] paramsToStore = new SqlParameter[1];
paramsToStore[0] = new SqlParameter("@tablename", SqlDbType.NVarChar);
paramsToStore[0].Direction=ParameterDirection.Input;
paramsToStore[0].Value=Tabellenname;
ds=nsn.core.SqlHelper.ExecuteDataset(connstring,CommandType.StoredProcedure,"main_searchtable",paramsToStore);
DataTable tbl=ds.Tables[0];
foreach(DataRow-Zeile in tbl.Rows)
{
ht_field.Add(row["Ansicht"].ToString(),row["Ansicht"].ToString());
//System.Web.HttpContext.Current.Response.Write(row["字段名"].ToString());
}
return(ht_field);
}
main_searchtable 存储过程是
PROZEDUR ERSTELLEN main_searchtable
@tablename nvarchar(50)
ALS
WÄHLEN
表名=Fall, wenn a.colorder=1 dann d.name else '' endet,
表说明=case when a.colorder=1 then isnull(f.value,'') else '' end,
字段序号=a.colorder,
字段名=ein.Name,
标识=Fall, wenn COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 dann '√'else '' endet,
类型=b.name
VON syscolumns a
Linker Join systypes b auf a.xtype=b.xusertype
Inner Join Sysobjects d auf a.id=d.id und d.xtype='U' und d.name<>'dtproperties'
Left Join sysproperties f auf d.id=f.id und f.smallid=0
where d.name=@tablename --如果只查询指定表,加上此条件
Reihenfolge nach a.id,a.colorder
GEHE
http://liuxiaoyi666.cnblogs.com/archive/2006/05/28/411082.html