关于以下代码,当我查询到数据,选择要删除的东西后,再查询数据时不出现任何东西,没有删除的数据也查询不到 只有把页面关掉重新查询才行 为什么? 请指教!! protected void Getdatabind()
{
Sda.SelectCommand = new SqlCommand();
Sda.SelectCommand.CommandTimeout = 180;
Sda.SelectCommand.Connection = con;
Sda.SelectCommand.CommandText = "LOTNO1";
Sda.SelectCommand.CommandType = CommandType.StoredProcedure; Sda.SelectCommand.Parameters.Add(new SqlParameter("@FDATE", SqlDbType.Char)).Value = TxtDate.Text;
Sda.SelectCommand.Parameters.Add(new SqlParameter("@Class", SqlDbType.NVarChar)).Value = DDLClass.SelectedValue.Trim();
if (con.State.ToString() == "Closed")
con.Open();
Sda.Fill(Ds, "QTYLOT");
GridView1.DataSource = Ds.Tables["QTYLOT"].DefaultView;
GridView1.DataBind(); con.Close(); }
protected void Button2_Click(object sender, EventArgs e)
{
Sda.DeleteCommand = new SqlCommand();
Sda.DeleteCommand .Connection = con;
Sda.DeleteCommand .CommandType = CommandType.Text;
Sda.DeleteCommand .CommandText = "DELETE FROM ITEM WHERE LOTNO='" + txtlot.Text + "' ";
if (con.State.ToString() == "Closed")
con.Open();
//SqlDataReader sdr = Sda.DeleteCommand.ExecuteReader();
int p = Sda.DeleteCommand.ExecuteNonQuery();
//GridView1.DataSource = sdr;
//GridView1.DataBind(); con.Close();
if (txtlot.Text != "")
{
labAlert.Visible = true;
GridView1.Visible = false;
txtlot.Text = "";
}
//else
//{
//}
}
解决方案 »
- ajax请求的问题。无法获取到传递过来的参数
- 使用eWebEditor 出现 msxml3.dll 错误 '80072ee2' 超时 /LM/W3SVC/519066790/Root/global.asa
- img 路径帮定问题
- 如何实现gridview无刷新的编辑、更新。。不是AJAX的
- 请问为什么我不能加载和新建asp.net程序 ?
- 在ASP.Net中如何在一个页面中调用其他页面TextBox中的值?求教!
- xml的读取问题?
- About alert() 请指点!
- asp.net下用水晶报表的小问题!
- ExecuteReader:CommandText 属性尚未初始化 ??????????????
- 新手关于Response.Write()使用Html角本求答
- 【提问】非哥。今天看你挺忙。有一个问题
{
Sda.DeleteCommand = new SqlCommand();
Sda.DeleteCommand .Connection = con;
Sda.DeleteCommand .CommandType = CommandType.Text;
Sda.DeleteCommand .CommandText = "DELETE FROM ITEM WHERE LOTNO='" + txtlot.Text + "' ";
if (con.State.ToString() == "Closed")
con.Open();
//SqlDataReader sdr = Sda.DeleteCommand.ExecuteReader();
int p = Sda.DeleteCommand.ExecuteNonQuery();
//GridView1.DataSource = sdr;
//GridView1.DataBind(); con.Close();
if (txtlot.Text != "")
{
labAlert.Visible = true;
GridView1.Visible = false;
txtlot.Text = "";
}
//else
//{
//}
Getdatabind(); }
if(!ispostback()) 也是不管用啊
具体怎么做呢?请指教!
以下是全部代码,请指教public partial class LotNo1 : System.Web.UI.Page
{
private SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Con"]);
private SqlDataAdapter Sda = new SqlDataAdapter();
private DataSet Ds = new DataSet(); protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DateTime td = DateTime.Now; string strMonth = "";
string strDay = ""; if (td.Month.ToString().Length < 2)
strMonth = "0" + td.Month.ToString();
else
strMonth = td.Month.ToString(); if (td.Day.ToString().Length < 2)
strDay = "0" + td.Day.ToString();
else
strDay = td.Day.ToString(); TxtDate.Text = td.Year.ToString() + "/" + strMonth + "/" + strDay;
TxtDate.Attributes.Add("onclick", "fPopCalendar(this)");
BindClass();
//Getdatabind();
}
}
private void BindClass()
{
DDLClass.Items.Clear(); ListItem lld_1 = new ListItem();
lld_1.Text = "全部";
lld_1.Value = "";
DDLClass.Items.Add(lld_1); ListItem lld_2 = new ListItem();
lld_2.Text = "A";
lld_2.Value = "A";
DDLClass.Items.Add(lld_2); ListItem lld_3 = new ListItem();
lld_3.Text = "B";
lld_3.Value = "B";
DDLClass.Items.Add(lld_3); ListItem lld_4 = new ListItem();
lld_4.Text = "C";
lld_4.Value = "C";
DDLClass.Items.Add(lld_4); } protected void Getdatabind()
{
Sda.SelectCommand = new SqlCommand();
Sda.SelectCommand.CommandTimeout = 180;
Sda.SelectCommand.Connection = con;
Sda.SelectCommand.CommandText = "LOTNO1";
Sda.SelectCommand.CommandType = CommandType.StoredProcedure; Sda.SelectCommand.Parameters.Add(new SqlParameter("@FDATE", SqlDbType.Char)).Value = TxtDate.Text;
Sda.SelectCommand.Parameters.Add(new SqlParameter("@Class", SqlDbType.NVarChar)).Value = DDLClass.SelectedValue.Trim();
if (con.State.ToString() == "Closed")
con.Open();
Sda.Fill(Ds, "QTYLOT");
GridView1.DataSource = Ds.Tables["QTYLOT"].DefaultView;
GridView1.DataBind(); con.Close(); }
protected void Button2_Click(object sender, EventArgs e)
{
Sda.DeleteCommand = new SqlCommand();
Sda.DeleteCommand .Connection = con;
Sda.DeleteCommand .CommandType = CommandType.Text;
Sda.DeleteCommand .CommandText = "DELETE FROM ITEM WHERE LOTNO='" + txtlot.Text + "' ";
if (con.State.ToString() == "Closed")
con.Open();
//SqlDataReader sdr = Sda.DeleteCommand.ExecuteReader();
int p = Sda.DeleteCommand.ExecuteNonQuery();
//GridView1.DataSource = sdr;
//GridView1.DataBind(); con.Close();
if (txtlot.Text != "")
{
labAlert.Visible = true;
GridView1.Visible = false;
txtlot.Text = "";
}
//else
//{
//}
Getdatabind();
}
protected void Button1_Click(object sender, EventArgs e)
{
Getdatabind();
}
}
至于SQL注入方面,我觉得 拼字符串的好使。
{
labAlert.Visible = true;
GridView1.Visible = false; 把这句去掉就行了 color]
txtlot.Text = "";
}谢谢大家!!!
{
labAlert.Visible = true;
GridView1.Visible = false; 把这句红色的去掉就行了
txtlot.Text = "";
} 谢谢大家!!!