SqlConnection con = new SqlConnection(); SqlCommand com = new SqlCommand(); SqlDataAdapter da; StringBuilder sb = new StringBuilder (); string strsql = ""; DateTime _newdate; DataTable dt = new DataTable(); DataSet ds = new DataSet (); string strcon = "Data Source=Computername;Initial Catalog=dbTest;Integrated Security=True"; private bool ConnectDB() { if (con.State == ConnectionState .Open ) { con.Close(); return false; } else { con.ConnectionString = strcon; con.Open(); return true; } } private DateTime GetDate_FromServer() { if (ConnectDB()) { sb.Remove(0, sb.Length); sb.Append("select GETDATE() as _getdate "); strsql = sb.ToString(); da = new SqlDataAdapter(strsql, con); if (ds.Tables["dt_data"] != null) { ds.Tables["dt_data"].Clear(); } da.Fill(ds, "dt_data"); dt = ds.Tables["dt_data"]; _newdate = Convert.ToDateTime(dt.Rows[0]["_getdate"]); con.Close(); return _newdate; } else { con.Close(); return _newdate = DateTime.Now ; } } private string _getMaxID() { string _strMaxId = ""; GetDate_FromServer(); if(ConnectDB()) { sb.Remove (0,sb.Length ); sb.Append ("select Max(ImportanceId) as maxid from Importance "); strsql = sb.ToString (); da = new SqlDataAdapter (strsql,con); if (ds.Tables ["dt_maxid"] != null) { ds.Tables["dt_maxid"].Clear(); } da.Fill (ds,"dt_maxid"); dt = ds.Tables["dt_maxid"]; string _cvDate = _newdate.ToString("yyMMdd"); if (dt.Rows.Count !=0) { int _maxId = Convert.ToInt32(dt.Rows[0]["maxid"]); int _idNew = _maxId +1; string strIDNew = _cvDate +"-"+ _idNew.ToString ("0000"); _strMaxId = strIDNew; } else { _strMaxId = _cvDate + "-" + "0001"; } } con.Close(); return _strMaxId; }
Private void Form1_Load(...) { string _newrunningId = _getMaxID(); }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง