gpt4 book ai didi

c# - 单击按钮后刷新 Gridview

转载 作者:行者123 更新时间:2023-11-30 16:19:37 26 4
gpt4 key购买 nike

在我的 asp.net 项目中,如何在单击我的按钮后立即刷新我的 gridview。我的按钮有更新代码。这是代码;

protected void Button3_Click(object sender, EventArgs e)
{
string strSQL = "UPDATE [bilgiler3] SET [HAM_FM] = ISNULL(MON,0)+ISNULL(TUE,0)+ISNULL(WED,0)+ISNULL(THU,0)+ISNULL(FRI,0)+ISNULL(SAT,0)+ISNULL(SUN,0) WHERE [DATE] BETWEEN @DATE1 AND @DATE2 AND WORK_TYPE='OUT'";
string connStr = WebConfigurationManager.ConnectionStrings["asgdb01ConnectionString"].ConnectionString;
using (SqlConnection conn = new SqlConnection(connStr))
{
using (SqlCommand comm = new SqlCommand())
{
comm.Connection = conn;
comm.CommandText = strSQL;
comm.CommandType = CommandType.Text;

comm.Parameters.AddWithValue("@DATE1", Convert.ToDateTime(TextBox1.Text));
comm.Parameters.AddWithValue("@DATE2", Convert.ToDateTime(TextBox2.Text));
try
{
conn.Open();
int i = comm.ExecuteNonQuery();
conn.Close();
if (i > 0)
{
Response.Write(" SUCCESS ");
}
else
{
Response.Write(" ERROR ! ");
}
}
catch (SqlException ex)
{
Response.Write(ex.ToString());
}
}
}
}

您可能会说“您需要绑定(bind) gridview 的数据”,但我无法理解该方法。你能帮我吗?

非常感谢。

最佳答案

我会做以下事情:

DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter();
SqlConnection sc = new SqlConnection("you connection string here Security=True");


private void loadData()
{
try
{
ds.Clear();
SqlCommand sCmd= new SqlCommand("Load your database", sc);
sda.SelectCommand = sCmd;
sda.Fill(ds, "sCmd");

datagrid.DataSource = ds.Tables["sCmd"];
}

catch (Exception ex)
{
MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.ExitThread();
}

}

C# 初学者的东西 Youtube

关于c# - 单击按钮后刷新 Gridview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15080032/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com