[請益] 關於C#用Calender做查詢

看板Programming作者 (Louis)時間15年前 (2010/08/06 09:44), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
各位好 小弟現在的作業環境為C#的webform 做一個查詢的功能,利用Calender所select的值與資料庫裡的Date資料做比對~如果查不 到或是空值~就會顯示"查無資料" 現在寫了一小段~但是出來的結果是 { 例外詳細資訊: System.NullReferenceException: 並未將物件參考設定為物件的執行個 體 原始程式錯誤: 行 51: GridView1.DataBind(); 行 52: } 行 53: GridView1.HeaderRow.Cells[1].Text = "消息編號"; 行 54: GridView1.HeaderRow.Cells[2].Text = "消息名稱"; 行 55: GridView1.HeaderRow.Cells[3].Text = "消息日期"; } 我寫的語法如下 protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { string connstr = ConfigurationManager.ConnectionStrings["Erlin"].ConnectionString; string sqlstr = "Select NewsID,NewsName, NewsDate From News where NewsDate = '" + Calendar1.SelectedDate.Date.ToShortDateString() + "' order by NewsID DESC" ; OleDbDataAdapter adpt = new OleDbDataAdapter(sqlstr, connstr); DataSet ds = new DataSet(); adpt.Fill(ds); if (Calendar1.SelectedDate.Date.ToShortDateString() != "NewsDate") { Label2.Text = "查無消息資料"; } else { GridView1.DataSource = ds; GridView1.DataBind(); } GridView1.HeaderRow.Cells[1].Text = "消息編號"; GridView1.HeaderRow.Cells[2].Text = "消息名稱"; GridView1.HeaderRow.Cells[3].Text = "消息日期"; } 有勞各位了...感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.230.221.176

08/14 23:08, , 1F
沒人回,我來回一下好了,你可到C#板
08/14 23:08, 1F
文章代碼(AID): #1CMsaPb2 (Programming)
文章代碼(AID): #1CMsaPb2 (Programming)