日期:2014-05-17  浏览次数:20910 次

判断语句
我写了一个备注页面 打开备注页面要显示数据库的信息 可是数据库里没有数据就会报错 我应该怎么写判断语句
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Common;

public partial class khgl_beizhu : System.Web.UI.Page
{
  string c_id = "";
  protected void Page_Load(object sender, EventArgs e)
  {
   
  if (!IsPostBack)
  {
  c_id = Request["c_id"] + "";
  binduser(c_id);
   
  }
  }

  private void binduser(string id)
  {
  string Sql = "select * from t_beizhu where c_id='" + c_id + "'";
  DataTable dt =conn.SqlQuery(Sql);
   
  gszz.Text = dt.Rows[0]["c_gszz"].ToString();
  gsjj.Text = dt.Rows[0]["c_gsjj"].ToString();
  jtlx.Text = dt.Rows[0]["c_jtlx"].ToString();
  khxq.Text = dt.Rows[0]["c_khxq"].ToString();
  jzzk.Text = dt.Rows[0]["c_jzzk"].ToString();
  xxh.Text = dt.Rows[0]["c_xxh"].ToString();
  qt.Text = dt.Rows[0]["c_qt"].ToString();
   
   
   
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  int id = Convert.ToInt16(Request.QueryString["id"]);
  string a = gszz.Text.ToString();
  string b = gsjj.Text.ToString();
  string c = jtlx.Text.ToString();
  string d = khxq.Text.ToString();
  string q = jzzk.Text.ToString();
  string f = xxh.Text.ToString();
  string g = qt.Text.ToString();




  if (Request["c_id"]+""!="")
  {
  string Sql = "Update t_beizhu set [c_gszz]='" + a + "',[c_gsjj]='"+ b +"',[c_jtlx]='"+c+"',[c_khxq]='"+d+"',[c_jzzk]='"+q+"',[c_xxh]='"+f+"',[c_qt]='"+g+"' where c_id=" + c_id + "";
  if (conn.ExecuteCommand(Sql)!= 0)
  {
  Response.Write("<script>alert('保存成功')</script>");
  Response.Write("<script>window.location='detail.aspx'</script>");
  }

  else
  {
  conn.Message(this, "保存失败!");
  }
   
  }
  else
  {
  string sql = "insert into t_beizhu (c_gszz,c_gsjj,c_jtlx,c_khxq,c_jzzk,c_xxh,c_qt) values ('" + gszz.Text + "','" + gsjj.Text + "','" + jtlx.Text + "','" + khxq.Text + "','" + jzzk.Text + "','" + xxh.Text + "','" + qt.Text + "')";

  if (conn.ExecuteCommand(sql) != 0)
  {
  Response.Write("<script>alert('添加成功')</script>");
  Response.Write("<script>window.location='detail.aspx'</script>");
  }

  }  
  }
}