求教谁用SqlHelper的问题
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using iyedu_mesbcnt;
public partial class ViewMsg : System.Web.UI.Page
{
basecnt dobase = new basecnt();
protected void Page_Load(object sender, EventArgs e)
{
string tid = Request.QueryString["NewsID"];
if (!dobase.isnumeric(tid))
{
Response.Write(dobase.messbox(1, "参数错误", "Default.aspx"));
Response.End();
}
SqlParameter myparm = new SqlParameter();
myparm.ParameterName = "id";
myparm.SqlDbType = SqlDbType.Int;
myparm.Size = 4;
myparm.Value = tid;
string sqlexec = "SelBxxsByParm";
SqlCommand cmd = new SqlCommand();
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
conn.Open();
SqlDataReader mydr =SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure,sqlexec,myparm);
if (mydr.Read())
{
lbltitle.Text = mydr["title"].ToString();
}
//SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, sqlexec, myparm);
//Dlist1.DataSource = mydr;
//Dlist1.DataBind();
}
}
}
存储过程SelBxxsByParm:
CREATE PROCEDURE SelBxxsByParm
@id int
AS
Select * from [Bxxsmsg] where id = @id
GO
出现以下问题:
编译错误
说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。
编译器错误信息: CS1502: 与“SqlHelper.ExecuteReader(string, System.Data.CommandType, string, params System.Data.SqlClient.SqlParameter[])”最匹配的重载方法具有一些无效参数
源错误:
行 34: {
行 35: conn.Open();
行 36: SqlDataReader mydr =SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure,sqlexec,myparm);
行 37: if (mydr.Read())
行 38: {
请大家帮我解决以下
------解决方案-------------------- SqlParameter[] myparm ={ new SqlParameter("@id",SqlDbType.Int,4)};
parameters[0].Value = tid;
sqlhelper SqlParameter要用数组
------解决方案-------------------- myparm应该定义成数组
------解决方案--------------------错误信息已经说的很详细了,使用的参数无效.检查你传递的参数类型和值是不是符合.
------解决方案--------------------仅看楼主提供的信息:
函数的签名:
public static SqlDataReader ExecuteReader(string connectionString, CommandType cmdType, string cmdText, params SqlParameter[] commandParameters)
而你调用的是:
using (SqlConnection conn = new SqlConnection(SqlHelper.ConnectionStringLocalTransaction))
{
conn.Open();
SqlDataReader mydr =SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure,sqlexec,myparm);
....
当然会出现这个 "无法从“
System.Data.SqlClient.SqlConnection”转换为“string” " 错误了.
同时看Page_Load里面的代码, 我觉得很奇