您的位置:首页 > 其它

哪位大侠给指点一下啊

2010-07-02 11:30 288 查看
关于自定义表单,我的思路是记录创建表单的项然后通过SQL过程创建数据表可是老是提示类型异常请各位帮忙看下到底哪里错了,谢谢

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- 根据要求创建表单
-- =============================================
ALTER PROCEDURE [dbo].[CreateTables]
@tablename nvarchar(100), --表名
@str nvarchar(1000) --字段
AS
declare @sql nvarchar(1100)
set @sql=''
BEGIN
set @sql='create table'+' '+@tablename+'('+@str+')'+';'
print @sql
execute (@sql)
--create table @tablename (@str)
END

asp.net调用如下

/// <summary>
/// connect 为连接字符串
/// process 为过程名
/// Sda为 SQL数据适配器
/// </summary>
SqlConnection connect;
SqlCommand process;
SqlDataAdapter Sda;
private string connectionString = ConfigurationManager.ConnectionStrings["oasysConnectionString"].ConnectionString;
public WorkFlow()
{
connect = new SqlConnection(connectionString);
this.process = connect.CreateCommand();
Sda = new SqlDataAdapter(this.process);
}

public void CreateTables(string names, string strs)
{
connect.Open();
process = new SqlCommand("CreateTables", connect);
process.CommandType = CommandType.StoredProcedure;
SqlParameter tablename = new SqlParameter("@tablename", SqlDbType.NVarChar, 100);
tablename.Value = names;
process.Parameters.Add(tablename);
SqlParameter str = new SqlParameter("@str", SqlDbType.NVarChar, 1000);
str.Value = strs;
process.Parameters.Add(str);
runprocess();
}
private void runprocess()
{
try
{
process.ExecuteNonQuery();
}
catch (Exception ex)
{
ex = new Exception("操作失败!");

throw ex;
}
finally
{
connect.Close();
}
}

页面文件

WorkFlow.WorkFlow WorkFlow = new WorkFlow.WorkFlow();
static string str = "";
static string route = "";
protected void Page_Load(object sender, EventArgs e)
{
//UpdatePanel1.Visible = true;
//UpdatePanel2.Visible = false;
//UpdatePanel3.Visible = false;
//if (!Page.IsPostBack)
//{

//}
}
protected void Button1_Click(object sender, EventArgs e)
{

try
{
WorkFlow.CreateWorkFlowTable(TextBox1.Text, "id", "int", "0", "IDENTITY(1,1) NOT NULL PRIMARY KEY", TextBox2.Text);
pClass.MessageBoxShow("创建表成功", "", Page);
str = TextBox1.Text + " " + "id" + " " + "int" + " " + "" + "IDENTITY(1,1) NOT NULL PRIMARY KEY"; //str记录创建表单的字段参数
UpdatePanel1.Visible = false;
UpdatePanel2.Visible = true;
UpdatePanel3.Visible = false;

tablenames.Text = TextBox1.Text;

}
catch
{
pClass.MessageBoxShow("创建表失败", "", Page);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
try
{
WorkFlow.CreateWorkFlowTable(tablenames.Text, TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text,TextBox7.Text);
pClass.MessageBoxShow("创建字段成功", "", Page);
str += "," + tablenames.Text + " " + TextBox3.Text + " " + TextBox4.Text + "(" + TextBox5.Text+")"+ " " + TextBox6.Text + " " + TextBox7.Text;

GridView1.DataBind();
TextBox7.Text = "";
TextBox6.Text = "";
TextBox5.Text = "";
TextBox4.Text = "";
TextBox3.Text = "";
//待定
}
catch
{
pClass.MessageBoxShow("创建字段失败", "", Page);
}
}
protected void Button3_Click(object sender, EventArgs e)
{
UpdatePanel1.Visible = false;
UpdatePanel2.Visible = false;
UpdatePanel3.Visible = true;
}
protected void Button4_Click(object sender, EventArgs e)
{
GridView3.DataBind();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Label Label1 = (Label)GridView3.FindControl("Label1");
TextBox TextBox8 = (TextBox)UpdatePanel3.FindControl("TextBox8");
TextBox8.Text = Label1.Text;
}
protected void Button5_Click(object sender, EventArgs e)
{
route += TextBox8.Text + "-";
str += "," + tablenames.Text + " " + TextBox8.Text + "sh" + " " + "nvarchar(200)" + " ";
WorkFlow.CreateWorkFlowTable(tablenames.Text, TextBox8.Text + "sh", "nvarchar(200)", "200", "", "");
TextBox8.Text = "";
TextBox9.Text = "";
//pClass.MessageBoxShow("节点输入成功", "");
routelabel.Text = route;

UpdatePanel3.DataBind();
}
protected void Button6_Click(object sender, EventArgs e)
{
//route += "'";
str += "," + "route" + " " + "nvarchar(500)" + " " + "default " + route;//记录流程节点
str += "," + "currents" + " " + "nvarchar(500)";//记录到哪里了
//str+=","+"
///daixu!!!!!!!!!!!!!!!!!!!!!!!!
}
protected void Button7_Click(object sender, EventArgs e)
{
try
{
WorkFlow.CreateTables(tablenames.Text, str);
pClass.MessageBoxShow("创建成功", "", Page);
}
catch
{

}
}

敢问我错在哪里了 谢谢
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐