62,177
社区成员
发帖
与我相关
我的任务
分享
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "";//数据连接字符串
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@title", SqlDbType.VarChar, 255).Value = TextBox1.Text.Trim();
cmd.Parameters.Add("@content", SqlDbType.VarChar, 255).Value = TextBox2.Text.Trim();
cmd.CommandText = "proc_insert";
cmd.ExecuteNonQuery();
conn.Close();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "";//数据连接字符串
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@title", SqlDbType.VarChar, 255).Value = TextBox1.Text.Trim();
cmd.Parameters.Add("@content", SqlDbType.VarChar, 255).Value = TextBox2.Text.Trim();
cmd.ExecuteNonQuery();
conn.Close();
create procedure proc_insert
(@title varchar(255),@content varchar(255))
AS
insert info(title,content)
select @title,@content
go
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "";//数据连接字符串
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.ExecuteNonQuery();
conn.Close();
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Server=(local);UID=sa;PWD=;DataBase=Article";//数据连接字符串
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@title", SqlDbType.VarChar, 255).Value = TextBox1.Text.Trim();
cmd.Parameters.Add("@content", SqlDbType.VarChar, 255).Value = TextBox2.Text.Trim();
cmd.CommandText = "a_insert";
cmd.ExecuteNonQuery();
conn.Close();
}
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><asp:Button ID="Button1"
runat="server" Text="Button" OnClick="Button1_Click" />
</div>
</form>
CREATE PROCEDURE a_insert
(@title varchar(255),@content varchar(255))
AS
insert into Article(title,content)values(@title,@content)
GO
create procedure 存储过程名
(
@name varchar (20),
@pwd varchar(10)
)
as
insert into (name,pwd)values(@name,@pwd)
go