asp.net调用存储过程的疑问
存储过程如下:
create proc sp_InsertUsers
@name varchar(20),
@password varchar(20),
@age int
as
insert into users values(@name,@password,@age)
asp.NET调用如下:
string name = TextBox1.Text.Trim();
string password = TextBox2.Text.Trim();
int age = Convert.ToInt32(TextBox3.Text.Trim().ToString());
using (coon=DataBase.getCon())//数据库链接 {
coon.Open();
adapter = new SqlDataAdapter();
adapter.SelectCommand=new SqlCommand();
adapter.SelectCommand.Connection=coon;
adapter.SelectCommand.CommandText = "sp_InsertUsers('name','password',age)";//传入参数
adapter. SelectCommand.CommandType = CommandType.StoredProcedure;
代码正常执行,但是数据始终进不了数据库。这种直接传入参数的写法我第一次用,希望高手帮忙。
------解决方案--------------------
C# code
adapter.InsertCommand=new SqlCommand();
adapter.InsertCommand.Connection=coon;
adapter.InsertCommand.CommandText = "sp_InsertUsers('name','password',age)";//传入参数
adapter. InsertCommand.CommandType = CommandType.StoredProcedure;
adapter.InsertCommand.ExecuteNonQuery();