嗨,任何人都可以帮助我不确定为什么我的按钮中的计数器无法正常工作,对所有其他代码感到抱歉。我想通过使用计数器来构建数据库中的数据。如果有更简单的方法也可以。
public partial class _Default : System.Web.UI.Page
{
int iDefualt = 2;
int iMainCounter = 0;
SqlConnection con1 = new SqlConnection("Data Source=EON;Initial Catalog=DW2;Persist Security Info=True;User ID=Kapow;Password=Kapow");
DataTable dt = new DataTable();
public void Page_Load(object sender, EventArgs e)
{
con1.Open();
SqlDataReader myReader = null;
//SqlCommand myCommand = new SqlCommand("select * from customer_registration where username='" + Session["username"] + "'", con1);
SqlCommand myCommand = new SqlCommand(sNavigate(0), con1);
/SELECT * FROM tblDW2 WHERE [User]='Petrus'
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
txtbxDaywords.Text = (myReader["Dayword"].ToString());
}
con1.Close();
iMainCounter = iDefualt;
// "Daywords\t" + "\n" + DateTime.Now.ToString();
}
public string sNavigate(int iNavNum)
{
int iNavigate;
if (iNavNum != 0)
{
iNavigate = iNavNum;
}
else
{
iNavigate = iDefualt;
}
return "SELECT * FROM (SELECT Dayword, ROW_NUMBER() OVER (ORDER BY Dayword) AS Rownumber FROM tblDW2 WHERE [User]='Petrus' ) results WHERE results.Rownumber = "+ iNavigate.ToString();
}
protected void btnNext_Click1(object sender, EventArgs e)
{
iMainCounter++;
con1.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand(sNavigate(iMainCounter), con1);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
txtbxDaywords.Text = (myReader["Dayword"].ToString());
}
con1.Close();
}
}