/// <summary>
/// 通过SQL语句和条件查询一条数据库信息
/// </summary>
/// <param name="safeSql">存储过程名</param>
/// <param name="values">存储过程参数值</param>
/// <returns>数据库信息数量</returns>
public int GetScalar(string safeSql, params SqlParameter[] values)
{
SqlCommand cmd = new SqlCommand(safeSql, Connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddRange(values);
int result = Convert.ToInt32(cmd.ExecuteScalar());
return result;
}
protected void Button2_Click(object sender, EventArgs e)
{
string shuru = TextBox1.Text;
SqlParameter param = new SqlParameter("@name", SqlDbType.NVarChar,50,shuru);
param.Value = shuru;
db.GetScalar("mohuselect");
db.DataBindGridView(GridView1, "mohuselect");
}
这是存储过程
create Procedure [dbo].[mohuselect]
@name nvarchar(50)
AS
BEGIN
SELECT*
FROM s_studentinfo
where name like '%'+@name+'%'
END
error其他信息: 过程或函数 'mohuselect' 需要参数 '@name',但未提供该参数
慕少森