如何使用C#在sql server中创建动态表 [英] how to create dynamic tables in sql server using C#
本文介绍了如何使用C#在sql server中创建动态表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据用户给出的输入,通过C#在sql server中创建动态表。
当用户给出他/她的名字时,c#代码必须在sql server中用他们的用户名创建表
EX:
create the dynamic tables in sql server through C# based on input given by the user.
when user giving his/her name the c# code has to create table in sql server in their user name
EX:
string crt_table = "create table"+ Textbob_dept.Text +"Faculty(FacultyID nchar(30),Username nchar(30),Password nchar(30))";
SqlCommand com_tbl = new SqlCommand(crt_table, cnn);
帮我理解一步一步的例子..
help me to understand with example in step by step process..
推荐答案
CREATE PROCEDURE sproc_CreateTableAtRuntime
@TableName NVARCHAR(128)
,@Column1Name NVARCHAR(32)
,@Column1DataType NVARCHAR(32)
,@Column1Nullable NVARCHAR(32)
AS
DECLARE @SQLString NVARCHAR(MAX)
SET @SQString = 'CREATE TABLE ' + @TableName + '( '+ @Column1Name + ' ' + @Column1DataType + ' '+ @Column1Nullable +') ON PRIMARY '
EXEC (@SQLString)
调用此sp并从c#代码发送上述参数
如果您需要更多列添加到我给出的存储过程中。
如果您认为列生成是动态的,那么只需从代码端发送列及其数据类型...如果您满意,请告诉我......如果您满意 请将其标记为答案
试试这些链接..
它会帮助你..
http://stackoverflow.com/questions/10033758/create-sql-table-programmatically [ ^ ]
http://stackoverflow.com/questions/19589020/c-sharp-create-sql-table-programmatically [<一个HREF =http://stackoverflow.com/questions/19589020/c-sharp-create-sql-table-p以编码方式target =_ blanktitle =New Window> ^ ]
http://stackoverflow.com/questions/4541050/creating-new-sql-server-table-with-c-sharp [ ^ ]
Try these links..
it'll help you..
http://stackoverflow.com/questions/10033758/create-sql-table-programmatically[^]
http://stackoverflow.com/questions/19589020/c-sharp-create-sql-table-programmatically[^]
http://stackoverflow.com/questions/4541050/creating-new-sql-server-table-with-c-sharp[^]
这篇关于如何使用C#在sql server中创建动态表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文