我刚开始使用我的 Visual Studio 2010,想要创建一个网站,我有 2 个下拉列表和 4 个文本框,用户可以从中输入数据和数据库应该更新但它没有发生,网格视图只是显示我的初始值的数据库。你能帮我得到想要的结果吗?
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.Sql;
namespace AppForSis
{
public partial class AppForSis : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection myConn = new SqlConnection(
"Data Source=HOME-AA3742A183;Initial Catalog=master;"
+ "Integrated Security=True");
myConn.Open();
SqlCommand up = new SqlCommand(
@"UPDATE
[resource1]
SET
[date_entered] = @d,
[pass] = @p,
[fail] = @f,
[blocked] = @b
WHERE ([rname] = @r)
AND ([mname] = @m)",
myConn);
up.Parameters.AddWithValue("@d", date.Text);
up.Parameters.AddWithValue("@p", pass.Text);
up.Parameters.AddWithValue("@f", fail.Text);
up.Parameters.AddWithValue("@b", blocked.Text);
up.Parameters.AddWithValue("@r", resource.SelectedValue);
up.Parameters.AddWithValue("@m", module.SelectedValue);
up.ExecuteNonQuery();
myConn.Close();
GridView1.Visible = true;
}
}
}