位置0处没有任何行
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.SqlClient;
public partial class vote : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string a = DateTime.Today.ToString();
SqlConnection Conn = new SqlConnection("server=ACDBA7FC19684F8\\SQLEXPRESS;database=abc;uid=zyl;pwd=123456");
//此处需改为自己的连接
string sql = "select * from vote where r1< '" + a + "' and r2 > '" + a + "' ";
SqlDataAdapter Comm = new SqlDataAdapter(sql, Conn);
DataSet ds = new DataSet();
Comm.Fill(ds, "vote");
if(ds.Tables[0].Rows.Count>0)
{
Label6.Text = ds.Tables[0].Rows[0]["title"].ToString();
Label1.Text = ds.Tables[0].Rows[0]["Vname1"].ToString();
Label3.Text = ds.Tables[0].Rows[0]["Vname2"].ToString();
Label5.Text = ds.Tables[0].Rows[0]["Vname3"].ToString();
Label7.Text = ds.Tables[0].Rows[0]["Vname4"].ToString();
}
else
{
Response.Write("表中无记录");
}
} --------------------编程问答-------------------- if(ds.Tables[0].Rows.Count>0) 这样判断不行。。
要判断列是否为空
为空了 ds.Tables[0].Rows[0]["Vname4"].ToString() 就错了
补充:.NET技术 , ASP.NET