private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { UpFile u = new UpFile(); u = u.Retrieveq(comboBox1.Text); comboBox1.DataSource = u.retrieveAllFile(); label1.Text = "公文標題:" + u.GetFileTitle(); label2.Text = "上傳日期:" + u.GetUpD(); label3.Text = "上傳時間:" + u.GetUpT(); textBox1.Text = u.GetFileContent(); }
public bool InsertUpFile(UpFile objUpFile) { Boolean tf = false; DBConnect dbconn = new DBConnect(); dbconn.ConnectDB(); try { Random r1 = new Random(); // 注意 : 字串要用單引號 ' ', 數字欄位不需要單引號 dbconn.getCmd().CommandText = "INSERT INTO FileData(FileNumber,Title,Content,FixContent,FileDate,UpTime,Status) VALUES('" + r1.Next(100000, 999999) + "','" + objUpFile.GetFileTitle() + "','" + objUpFile.GetFileContent() + "','無" + "','" + objUpFile.GetUpD() + "','" + objUpFile.GetUpT() + "','0" + "')"; dbconn.getCmd().CommandType = System.Data.CommandType.Text; dbconn.getConn().Open(); dbconn.getCmd().ExecuteNonQuery(); tf = true; } catch (Exception e) { System.Console.WriteLine("Error message :" + e.ToString()); } finally { if (dbconn.getConn() != null) { dbconn.getConn().Close(); } }; return(tf); }