过程或函数 'Byname' 需要参数 '@SiteID',但未提供该参数。
代码如下单击获取TEXTbox值protectedvoidbutnokClick(objectsender,EventArgse){stringPostName=txtn...
代码如下
单击获取TEXTbox 值
protected void butnokClick(object sender, EventArgs e)
{
string PostName = txtname.Text.ToString();
string PostContent = txtpwd.Text.ToString();
string siID = txtuserid.Text.ToString();
string Postdz = txttype.Text.ToString();
string Postdh = Textphone1.Text.ToString();
string Postfzr = Textfzr.Text.ToString();
if (InsertUser(PostName, PostContent, siID, Postdz, Postdh, Postfzr))
{
Response.Write("<script>alert(添加成功');</script>");
station_sql.EditIndex = -1;//取消编辑模式
station_sql.DataSource = SelAllUser();
station_sql.DataBind();
}
else
{
Response.Write("<script>alert('添加失败');</script>");
}
}
存入数据库代码
public bool InsertUser(string SCPwd, string SIName, string SIID, string SIds, string SIdh, string SIfzr)
{
//连接数据库
//command,更新数据的SQL
SqlConnection conn = new SqlConnection(conString);
try
{ //开启连接;
if (conn.State == ConnectionState.Closed) conn.Open();
//2.建立commnd
SqlCommand comm = new SqlCommand("Byname", conn);
SqlParameter[] pars = new SqlParameter[]{
new SqlParameter("@SiteID",SCPwd),
new SqlParameter("@SiteName",SIName),
new SqlParameter("@SCityID",SIID),
new SqlParameter("@SAddress",SIds),
new SqlParameter("@Sphone",SIdh),
new SqlParameter("@SResponsibilityID",SIfzr),
};
comm.Parameters.AddRange(pars);
int i = comm.ExecuteNonQuery();
//定义一个变量来接取comm返回的值
if (i > 0)//
return true;
else
return false;
//如果是查询数据,用datareader去读取数据,就调用executereader方法
//如果是查询数据,用dataadapter去读取数据,不需调用sqlcommand的任何方法,new sqldataadapter (comm)
//3.处理数据
}
catch
{
throw;
}
finally
{
//关闭连接
if (conn.State == ConnectionState.Open)//关闭数据库
conn.Close();
}
}
存储过程
ALTER proc [dbo].[Byname] --sp_GetTesttableByname代表存储过程名称
@SiteID int,
@SiteName int,
@SCityID int,
@SAddress int,
@Sphone int,
@SResponsibilityID int
as
begin
insert into SiteInfo (SiteID,SiteName,SCityID,SAddress,Sphone,SResponsibilityID)
values (@SiteID,@SiteName,@SCityID,@SAddress,@Sphone,@SResponsibilityID)
end 展开
单击获取TEXTbox 值
protected void butnokClick(object sender, EventArgs e)
{
string PostName = txtname.Text.ToString();
string PostContent = txtpwd.Text.ToString();
string siID = txtuserid.Text.ToString();
string Postdz = txttype.Text.ToString();
string Postdh = Textphone1.Text.ToString();
string Postfzr = Textfzr.Text.ToString();
if (InsertUser(PostName, PostContent, siID, Postdz, Postdh, Postfzr))
{
Response.Write("<script>alert(添加成功');</script>");
station_sql.EditIndex = -1;//取消编辑模式
station_sql.DataSource = SelAllUser();
station_sql.DataBind();
}
else
{
Response.Write("<script>alert('添加失败');</script>");
}
}
存入数据库代码
public bool InsertUser(string SCPwd, string SIName, string SIID, string SIds, string SIdh, string SIfzr)
{
//连接数据库
//command,更新数据的SQL
SqlConnection conn = new SqlConnection(conString);
try
{ //开启连接;
if (conn.State == ConnectionState.Closed) conn.Open();
//2.建立commnd
SqlCommand comm = new SqlCommand("Byname", conn);
SqlParameter[] pars = new SqlParameter[]{
new SqlParameter("@SiteID",SCPwd),
new SqlParameter("@SiteName",SIName),
new SqlParameter("@SCityID",SIID),
new SqlParameter("@SAddress",SIds),
new SqlParameter("@Sphone",SIdh),
new SqlParameter("@SResponsibilityID",SIfzr),
};
comm.Parameters.AddRange(pars);
int i = comm.ExecuteNonQuery();
//定义一个变量来接取comm返回的值
if (i > 0)//
return true;
else
return false;
//如果是查询数据,用datareader去读取数据,就调用executereader方法
//如果是查询数据,用dataadapter去读取数据,不需调用sqlcommand的任何方法,new sqldataadapter (comm)
//3.处理数据
}
catch
{
throw;
}
finally
{
//关闭连接
if (conn.State == ConnectionState.Open)//关闭数据库
conn.Close();
}
}
存储过程
ALTER proc [dbo].[Byname] --sp_GetTesttableByname代表存储过程名称
@SiteID int,
@SiteName int,
@SCityID int,
@SAddress int,
@Sphone int,
@SResponsibilityID int
as
begin
insert into SiteInfo (SiteID,SiteName,SCityID,SAddress,Sphone,SResponsibilityID)
values (@SiteID,@SiteName,@SCityID,@SAddress,@Sphone,@SResponsibilityID)
end 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |