如何检索SqlDataAdapter sda = new SqlDataAdapter(strsql, conn);是否执行
Stringstrcon="DataSource=(local);Initialcatalog=Ticket;IntegratedSecurity=True";SqlCo...
String strcon = "Data Source=(local);Initial catalog=Ticket;Integrated Security=True";
SqlConnection conn = new SqlConnection();
conn = new SqlConnection(strcon);
conn.Open();
string strsql = "select * from tb_Ticket where Tnum like'%" + TextBox1.Text.Trim() + "%'and StartingPoint ='" + DropDownList1.SelectedItem.Text.Trim() + "'and EndPoint='" + DropDownList2.SelectedItem.Text.Trim() + "'";
SqlDataAdapter sda = new SqlDataAdapter(strsql, conn);
DataSet ds = new DataSet();
sda.Fill(ds, "ticket");
GridView1.DataKeyNames = new string[] { "ID" };
GridView1.DataSource = ds.Tables["ticket"];
Session["ID"] = GridView1.DataKeyNames;
GridView1.DataBind();
如果执行了 想弹出个提示 该怎么写代码 展开
SqlConnection conn = new SqlConnection();
conn = new SqlConnection(strcon);
conn.Open();
string strsql = "select * from tb_Ticket where Tnum like'%" + TextBox1.Text.Trim() + "%'and StartingPoint ='" + DropDownList1.SelectedItem.Text.Trim() + "'and EndPoint='" + DropDownList2.SelectedItem.Text.Trim() + "'";
SqlDataAdapter sda = new SqlDataAdapter(strsql, conn);
DataSet ds = new DataSet();
sda.Fill(ds, "ticket");
GridView1.DataKeyNames = new string[] { "ID" };
GridView1.DataSource = ds.Tables["ticket"];
Session["ID"] = GridView1.DataKeyNames;
GridView1.DataBind();
如果执行了 想弹出个提示 该怎么写代码 展开
2个回答
展开全部
String strcon = "Data Source=(local);Initial catalog=Ticket;Integrated Security=True";
DataSet ds = new DataSet();
using(SqlConnection conn = new SqlConnection())
{
conn = new SqlConnection(strcon);
conn.Open();
string strsql = "select * from tb_Ticket where Tnum like'%" + TextBox1.Text.Trim() + "%'and StartingPoint ='" + DropDownList1.SelectedItem.Text.Trim() + "'and EndPoint='" + DropDownList2.SelectedItem.Text.Trim() + "'";
try
{
SqlDataAdapter sda = new SqlDataAdapter(strsql, conn);
sda.Fill(ds, "ticket");
}catch(Exception ex){
throw ex.ToString();
}
if(dt.rows.count>0)
{
Response.Write("<script>alert('已经执行并成功')</script>");
}
GridView1.DataKeyNames = new string[] { "ID" };
GridView1.DataSource = ds.Tables["ticket"];
Session["ID"] = GridView1.DataKeyNames;
GridView1.DataBind();
PS:如果语句没问题并已经检索执行【SqlDataAdapter sda = new SqlDataAdapter(strsql, conn);】则返回已经执行并成功,如果语句有问题则报黄页,如果执行成功数据库为空则什么都不做。
DataSet ds = new DataSet();
using(SqlConnection conn = new SqlConnection())
{
conn = new SqlConnection(strcon);
conn.Open();
string strsql = "select * from tb_Ticket where Tnum like'%" + TextBox1.Text.Trim() + "%'and StartingPoint ='" + DropDownList1.SelectedItem.Text.Trim() + "'and EndPoint='" + DropDownList2.SelectedItem.Text.Trim() + "'";
try
{
SqlDataAdapter sda = new SqlDataAdapter(strsql, conn);
sda.Fill(ds, "ticket");
}catch(Exception ex){
throw ex.ToString();
}
if(dt.rows.count>0)
{
Response.Write("<script>alert('已经执行并成功')</script>");
}
GridView1.DataKeyNames = new string[] { "ID" };
GridView1.DataSource = ds.Tables["ticket"];
Session["ID"] = GridView1.DataKeyNames;
GridView1.DataBind();
PS:如果语句没问题并已经检索执行【SqlDataAdapter sda = new SqlDataAdapter(strsql, conn);】则返回已经执行并成功,如果语句有问题则报黄页,如果执行成功数据库为空则什么都不做。
追问
conn是using指令 无法赋值
其实我想做的是如果没有执行提示一个报错 也就是GridView1没有显示东西的时候弹出一个报错
追答
if(dt.rows.counalert('已经执行并成功')");
}
这样就可以肯定没有值了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询