日期:2014-05-18 浏览次数:20351 次
这是我的代码,我在网上找了很久,也知道它错的原因,但我还是不能改好它。还希望帮我优化一下我的代码。谢谢... string cnsql = "server=.;database=wuliu;Integrated Security=SSPI"; SqlConnection mycon = new SqlConnection(cnsql); mycon.Open(); string str = "select * from dingdan where ID = '" + Session ["danhao"] + "'"; SqlCommand cmd = new SqlCommand(); cmd.Connection = mycon; cmd.CommandText = "select * from dingdan where ID = '" + Session["danhao"] + "'"; SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { SqlDataAdapter sda = new SqlDataAdapter(str, mycon); DataSet ds = new DataSet(); sda.Fill(ds, "mytb"); DataView dv = ds.Tables["mytb"].DefaultView; GridView1.DataSource = dv; GridView1.DataBind(); dr.Close(); } else { Response.Write("<script language='javascript'> alert('查询不到你的订单号,请电我们公司电话核实') ;window.location.href = 'index.aspx';</script>"); } mycon.Close();
string cnsql = "server=.;database=wuliu;Integrated Security=SSPI"; SqlConnection mycon = new SqlConnection(cnsql); mycon.Open(); string str = "select * from dingdan where ID = '" + Session ["danhao"] + "'"; SqlDataAdapter sda = new SqlDataAdapter(str, mycon); DataSet ds = new DataSet(); sda.Fill(ds, "mytb"); if(ds.Tables["mytb"].Rows.Count>0) { DataView dv = ds.Tables["mytb"].DefaultView; GridView1.DataSource = dv; GridView1.DataBind(); dr.Close(); } else { Response.Write("<script language='javascript'> alert('查询不到你的订单号,请电我们公司电话核实') ;window.location.href = 'index.aspx';</script>"); } mycon.Close();