各位老大:怎样在webform下自动创建sqlsever数据库,表,存储过程?

调用批处理命令吗?
---------------------------------------------------------------

如果没用特殊要求直接使用SqlCommand.ExecuteNonQuery()执行SQL语句就行。
---------------------------------------------------------------

有个最简单的办法:在程序里运行一个存储过程,该存储过程是执行RESTORE DATABASE 数据库的。
---------------------------------------------------------------

alter procedure dbo.addp @id int output,@name nvarchar(40),@supplierid int,@Categorid int as insert into Proudcts(productname,supplierid,categoryid)
values(@name,@supplierid@Categorid)
select@id=SOPE_INDENTITY()/also=(select max(id)or count()from products))
==========Main()
SqlConnection conn=new SqlConnection("server=localhost";database=Northwind;uid=sa;pwd=");
SqlCommand comm=conn.CreatCommand();
comm.CommandText="AddP@Id OUTPUT,@name,@supplierid,@Categoryid";
comm.Parameters.Add("@id",SqlDbType.Int);
comm.Parameters["@id"].Direction=ParameterDiection.Output;
comm.Parameters.Add("@Name",SqlDbType.NVarChar,40).Value="Widget";
comm.Parameters.Add("@SupplierID",SqlDbType.Int).Value=1;
comm.Parameters.Add("@Categoryid",SqlDbType.Int).Value=1;
comm.ExecuteNonQuery();
Response.Write("New Prodcutid")="+comm.Parameters["@id"].Value);
conn.close();
---------------------------------------------------------------

SqlCommand .
---------------------------------------------------------------

呵呵厉害三大巨星回答楼主的问题~~~

Published At
Categories with Web编程
Tagged with
comments powered by Disqus