using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace dbmanage
{
public partial class DBInformation : System.Web.UI.Page
{
SqlConnection sqlcon;
SqlCommand sqlcom;
string strCon = System.Configuration.ConfigurationManager.AppSettings["conn"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlCommand newCmd = new SqlCommand("select * from [db] where id=@id");
binddata(newCmd);
}
}
private void binddata(SqlCommand cmd)
{
string ID = Request.QueryString["id"];
cmd.Parameters.Add("@id", SqlDbType.NChar,10).Value = ID;
sqlcon = new SqlConnection(strCon);
SqlDataAdapter myda = new SqlDataAdapter(cmd.CommandText, sqlcon);
DataSet myds = new DataSet();
myda.Fill(myds);
DetailsView1.DataSource = myds.Tables[0];
DetailsView1.DataKeyNames = new string[] { "ID" };
DetailsView1.DataBind();
}
}
}
跳转到该页面时ID 获取正常 但是提示
反正就是这个@id的问题,你围着它仔细看看,就会找到的。
myda.SelectCommand.Parameters.Add("@id", SqlDbType.NChar, 10).Value = ID;