且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在使用C#和Sql Server 2005的ASP.net中使用存储过程

更新时间:2022-11-28 18:41:06

试试这个



如何调用存储过程asp.net c#code [ ^ ]



http://www.c-sharpcorner.com/UploadFile/gtomar/storedprocedure12052007003126AM/storedprocedure.aspx [ ^ ]
try this

how to call stored procedure in asp.net c# code[^]

http://www.c-sharpcorner.com/UploadFile/gtomar/storedprocedure12052007003126AM/storedprocedure.aspx[^]


看看这里:

如何创建带参数的SQL Server存储过程 [ ^ ]

使用存储过程和命令 [ ^ ]

如何:使用EntityCommand执行参数化存储过程 [ ^ ]

http://support.microsoft.com/kb/310070 [ ^ ]



启动是否足够?
Have a look here:
How to create a SQL Server stored procedure with parameters[^]
Using Stored Procedures with a Command[^]
How to: Execute a Parameterized Stored Procedure Using EntityCommand[^]
http://support.microsoft.com/kb/310070[^]

Is it enough for start?


>


你可以试试这样的东西





Hi,

you can try some thing like this


create procedure insert_data
(
    @Id int, @Name Varchar(20) , @address varchar(50)
)
begin

Insert into table1(Id,Name,address) values(@Id,@Name,@address)

end







您可以使用以下c#代码点击按钮来插入数据






you can use the following c# code on button click to insert data

try
  {
     sqlConnection  con = new SqlConnection(dbConnectionString);
     SqlCommand comm= new SqlCommand("insert_data", con);
     comm.CommandType = CommandType.StoredProcedure;
     comm.Parameters.Add("@Id", SqlDbType.VarChar).Value = txtId.Text;
     comm.Parameters.Add("@Name", SqlDbType.DateTime).Value = txtName.Text;
     comm.Parameters.Add("@Address", SqlDbType.DateTime).Value = txtaddress.Text;
     sqlConnection.Open();
     return comm.ExecuteNonQuery();
     sqlConnection.Close();
  }
catch (SqlException ex)
  {
     Console.WriteLine("SQL Error" + ex.Message.ToString());
     return 0;
  }





我希望它能帮到你..



I hope it will help you..