Post by Goborijung at 2022-04-19 10:48:18 | ID: 1466
string s = "This is a book"; string rep = s.Replace("book", "pencil"); // Output : This is a pencil
Post by Goborijung at 2020-09-14 09:04:27 | ID: 790
private void InitialGrid() { //DataGridView : dgS dgS.Rows.Clear(); dgS.ColumnHeadersDefaultCellStyle.BackColor = Color.Navy; dgS.ColumnHeadersDefaultCellStyle.ForeColor = Color.White; dgS.CellBorderStyle = DataGridViewCellBorderStyle.Single; dgS.GridColor = Color.Black; dgS.Columns[0].HeaderText = "Check"; dgS.Columns[1].HeaderText = "Customer"; }
Post by Goborijung at 2020-10-10 14:35:55 | ID: 770
private void ShowRowNumber(DataGridView dgvName) { //dgvName.RowHeadersWidth = 50; for (int i = 0; i < dgvName.Rows.Count; i++) { dgvName.Rows[i].HeaderCell.Value = (i + 1).ToString(); } // ถ้าจะใช้ใน Function โดยตรง ให้วางไว้หลัง dgvName.DataSource = xxx; }
Post by Goborijung at 2020-08-29 14:37:16 | ID: 759
>> Syntax MessageBox.Show("ข้อความ","Title"); >> ตัวอย่างที่ 1 string title = "This is Titlle"; string message = "Hello MessageBox"; MessageBox.Show(message); //แสดง Message Box MessageBox.Show(message,title); //แสดง Message Box พร้อม Title >> ตัวอย่างที่ 2 int num = 3_000_000; MessageBox.Show(num.ToString(),"ข้อความ Title"); MessageBox.Show("Hello C#" , "This Title");
Post by Goborijung at 2020-09-02 13:06:53 | ID: 678
Syntax : FormName fn = new FormName(); fn.Show();
EX. WEB_CuttingF4 WF4 = new WEB_CuttingF4(); WF4.Show();
Post by Goborijung at 2020-12-04 08:23:36 | ID: 766
private void btnAddByForm_Click(object sender, EventArgs e) { string name = txtName.Text.ToString(); string sql = "INSERT INTO Employee(FirstName,LastName) VALUES('"+name+"','"+name+"')"; //string sql = "UPDATE Employee SET FirstName='"+name+"',LastName='"+name+"' WHERE OID = "+oid+" "; //string sql = "DELETE Employee WHERE OID = "+oid+" "; SqlCommand cmd = new SqlCommand(sql, conn); try { conn.Open(); cmd.ExecuteNonQuery(); MessageBox.Show("ดำเนินการเรียบร้อยแล้ว."); conn.Close(); loadDVG(); } catch (Exception ex) { MessageBox.Show("Can not Open Connection! on cmdInsert"); } }
Post by Goborijung at 2020-09-10 16:00:53 | ID: 765
private void txtOID_KeyUp(object sender, KeyEventArgs e) { string sql = "SELECT * FROM Employee Where OID = "+txtOID.Text.ToString()+" "; Console.WriteLine(sql); try { conn.Open(); SqlCommand cmd = new SqlCommand(sql,conn); SqlDataReader dr = cmd.ExecuteReader(); dr.Read(); txtName.Text = dr.GetSqlValue(1).ToString(); //หรือ dr.GetValue(1).ToString(); หรือ dr["FName"].ToString(); dr.Close(); cmd.Dispose(); conn.Close(); } catch (Exception ex) { //MessageBox.Show("Can not Open Connection! on Keyup"); } Console.WriteLine(conn.State); }
Post by Goborijung at 2020-09-10 16:00:25 | ID: 764
private void btnDaDs_Click(object sender, EventArgs e) { string sql = "SELECT [OID],[FirstName],[LastName],[Phone],[Section] FROM Employee"; Console.WriteLine(sql); SqlDataAdapter da = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); try { conn.Open(); da.Fill(ds, "em"); conn.Close(); dataGridView1.DataSource = ds; dataGridView1.DataMember = "em"; } catch (Exception ex) { MessageBox.Show("Can not Open Connection! on DataAdapter"); } }
Post by Goborijung at 2022-02-24 11:18:16 | ID: 1377
string str = "GeeksForGeeks": str.ToUpper(); Output: GEEKSFORGEEKS
Post by Goborijung at 2020-09-22 11:26:17 | ID: 815
ตัวอย่าง string strVal = "Hello"; strVal.Substring(0, 2); //Output : He // เอา 3 ตัวสุดท้าย string str = "AM0122200204"; string substr = str.Substring(str.Length - 3); // Out : 204