表:Create table userName
(
int id identity(1,1) primary key,
userName varchar(30),not null
passWord varchar(30),not null
)存储过程:
Create procedure AddUserName
@userName varchar(30),
@passWord varchar(30)
as
begin
insert into(userName,passWord) values(@passWord ,@passWord )
endCreate procedure UpdateUser
@id,
@userName varchar(30),
@passWord varchar(30)
as
begin
update userName set userName=@userName,passWord=@passWord where id=@id
endCreate procedure GetUserName
@id int
as
begin
select * from userName where id=@id
endCreate procedure DeleteUserName
@id int
as
begin
delete from userName where id=@id
end
问题:
用存储过程去操作DataGrid 的添删改选,最好给我一个例子,也可以给出解决思路.
谢谢,高手指点.
(
int id identity(1,1) primary key,
userName varchar(30),not null
passWord varchar(30),not null
)存储过程:
Create procedure AddUserName
@userName varchar(30),
@passWord varchar(30)
as
begin
insert into(userName,passWord) values(@passWord ,@passWord )
endCreate procedure UpdateUser
@id,
@userName varchar(30),
@passWord varchar(30)
as
begin
update userName set userName=@userName,passWord=@passWord where id=@id
endCreate procedure GetUserName
@id int
as
begin
select * from userName where id=@id
endCreate procedure DeleteUserName
@id int
as
begin
delete from userName where id=@id
end
问题:
用存储过程去操作DataGrid 的添删改选,最好给我一个例子,也可以给出解决思路.
谢谢,高手指点.
解决方案 »
- 分页后第二页以后的数据无法获取(JS)
- 从DataSet中取数据的问题
- 请教傻瓜安装程序怎么做?
- 页面回发之后实现与原来相反的js效果
- 框架间通过HTML页传值的问题
- 如何将datagrid先前选中行的颜色?
- 求教:asp.net下的windows身份验证的问题?
- 高分求解,请各位帮忙!急,在线等
- [加50分求助] ( select * from 表名 where function(@col)='关键字' ) 其中@col是一个字符串变量,代表‘表’中某个字段,有function(@col
- 简单的数据绑定问题
- 有关ASP.Net 2.0 中的身份验证、角色验证,不知道能不能实现,如果有答复200分奉上!
- 'TextBox txt = (TextBox)e.Item.Cells.Controls[0];转换成VB.NET的语法怎么写啊,谢谢
http://singlepine.cnblogs.com/articles/266538.html
http://singlepine.cnblogs.com/articles/281425.html其他类似改法
private void Button1_Click(object sender, System.EventArgs e)
{
SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand comm=new SqlCommand("AddUserName",conn);
comm.CommandType=CommandType.StoredProcedure; SqlParameter parm1=new SqlParameter("@UserName",SqlDbType.NVarChar,50);
parm1.Value=this.TextBox1.Text; SqlParameter parm2=new SqlParameter("@passWord ",SqlDbType.NVarChar,50);
parm2.Value=this.DropDownList1.SelectedValue; comm.Parameters.Add(parm1);
comm.Parameters.Add(parm2);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
DataBind();
}
private void DataBind()
{
string sql="select * from testgrid";
DataSet ds=GetDataSet(sql);
this.DataGrid1.DataSource=ds;
this.DataGrid1.DataBind();
}
public DataSet GetDataSet()
{
SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand comm=new SqlCommand("AddUserName",conn);
comm.CommandType=CommandType.StoredProcedure; SqlParameter parm1=new SqlParameter("@UserName",SqlDbType.NVarChar,50);
parm1.Value=this.TextBox1.Text; SqlParameter parm2=new SqlParameter("@passWord ",SqlDbType.NVarChar,50);
parm2.Value=this.DropDownList1.SelectedValue; comm.Parameters.Add(parm1);
comm.Parameters.Add(parm2);
SqlDataAdapter cmdAdp=new SqlDataAdapter();
cmdAdp.SelectCommand=cmd;
DataSet ds=new DataSet();
con.Open();
cmdAdp.Fill(ds);
con.Close();
return ds;}然后只要 DataGrid.DataSource=GetDataSet();
DataGrid.DataBind();
//连接本地计算机的MMS数据库
SqlConnection cn= new SqlConnection (strconn);
cn.Open ();
SqlCommand cm=new SqlCommand ("login",cn);
cm.CommandType=CommandType.StoredProcedure; cm.Parameters.Add("@sql1",SqlDbType.NVarChar,50);
cm.Parameters["@sql1"].Value = tbx_uid.Text;
cm.Parameters.Add("@sql2",SqlDbType.NVarChar,50);
cm.Parameters["@sql2"].Value = tbx_upassword.Text;
SqlDataReader dr=cm.ExecuteReader ()存储过程:
CREATE proc login
(
@sql1 nvarchar(50),
@sql2 nvarchar(50)
)
AS
select * from lw_users where username=@sql1 and password=@sql2;
RETURNGO