2. เปิดโปรแกรม iReport Designer แล้วเลือก Menu: Tools->Options ดังรูป
private void button1_Click(object sender, EventArgs e)
{
//ช่วงที่ 1 เตรียมสร้างเอกสาร
object missing = System.Reflection.Missing.Value;
Excel.Application exApp = new Excel.ApplicationClass();
exApp.Visible = true;
Excel.Workbook exBook = exApp.Workbooks.Add(missing);
Excel.Worksheet exSheet = (Excel.Worksheet)exBook.Sheets["Sheet1"];
exSheet.Name = "Example";
//ช่วงที่ 2 เขียนข้อมูลลงไฟล์ Excel
exSheet.Cells[1, 1] = "TEST";
exSheet.Cells[1, 2] = "ABCD";
//ช่วงที่ 3 อ่านข้อมูลจากเอกสาร Excel สามารถเขียนได้สองแบบ
MessageBox.Show((string)((Excel.Range)exSheet.Cells[1,2]).Text);
MessageBox.Show(exSheet.get_Range("A1", "A1").Value2.ToString());
}
using System.Globalization;
.....
DateTimeFormatInfo myDTFI = new CultureInfo("en-US", false).DateTimeFormat;
Console.WriteLine(DateTime.Now.ToString(myDTFI));
Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd", myDTFI));
foreach(Control ctrl in this.Controls)
{
if((ctrl.Tag as string) == "lock")
{
ctrl.Enabled = true;
}
}
private void disableForm(bool status)
{
foreach(Control ctrl in this.Controls)
{
if(ctrl.Tag as string) == "lock")
{
ctrl.Enabled = status;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace ConsoleApplication9
{
// กำหนดตัวแปรเป็นชนิด T ภายใต้เครื่องหมาย "< >"
public class myCollection<T>
{
// นำชนิดตัวแปรนั้นมาใช้งานเช่นเดียวกับชนิดตัวแปรอื่นๆ
T[] myStack = new T[50];
  public T this[int idx]
{
get
{
return myStack[idx];
}
set
{
myStack[idx] = value;
}
}
}
public class Student
{
private String _std;
public Student(String name)
{
_std = name;
}
public override string ToString()
{
return _std;
}
}
class Program
{
static void Main(string[] args)
{
// เมื่อนำมาใช้งาน ให้กำหนดชนิดของตัวแปรตามที่ต้องการ ในที่นี้ให้แทนด้วย Class Student ที่ได้กำหนดไว้ (อาจกำหนดเป็น String, Int, ... ก็ได้แล้วแต่จะใช้)
myCollection<Student> mCollec = new myCollection<Student>();
//หลังจากที่กำหนดเรียบร้อยแล้ว จะสามารถนำตัวแปรนั้นมาใช้งานได้ทันที โดยชนิดของตัวแปรนั้นจะเป็นไปตามที่กำหนดไว้ในขั้นตอนการประการตัวแปร
mCollec[0] = new Student("Jor");
mCollec[1] = new Student("Ann");
mCollec[2] = new Student("Aae");
for(int item = 0; item < 3; item++)
Console.WriteLine(mCollec[item]);
Console.ReadKey();
}
}
}
จากขั้นตอนดังกล่าวจะเห็นว่าเมื่อเริ่มต้นนั้นการวนรอบของ foreach นั้นตำแหน่งของ Current นั้นจะต้องชี้ไปยังตำแหน่งก่อนหน้าค่าแรก (ในกรณีที่เป็น array ที่มีตำแหน่งเริ่มต้นที่ array[0] ตำแหน่งของ current จะต้องชี้ที่ตำแหน่ง -1) เนื่องจาก foreach จะเรียกใช้คำสั่ง MoveNext (ตำแหน่ง 1.3) ก่อนแล้วจึงส่ง element ใน collector ออกไป ดังนั้นในตอนที่สร้าง MyList ขึ้นมาจึงได้สร้าง node ใหม่ให้กับ _firstNode ในทันทีเพื่อป้องกันความผิดพลาดที่จะเกิดจากการอ่านข้อมูลจาก object ที่ไม่มีการอ้างถึง
class Containerจากตัวอย่าง code ข้างต้นจะเห็นว่าภายใน class Container จะมี class ภายใน ซึ่งเราจะเรียกว่า Nested Class โดยปกติแล้้ว การมองเห็น Nested จะเป็น private แต่เราสามารถเปลี่ยนรูปแบบการมองเห็นเป็นแบบอื่นได้ เช่น public, protected เป็นต้น
{
class Nested
{
Nested() {}
}
}
public class Containerการอ้างถึง Nested Class จากภายนอกสามารถทำได้โดย
{
public class Nested
{
private Container m_parent;
public Nested()
{
}
public Nested(Container parent)
{
m_parent = parent;
}
}
}
Container.Nested nest = new Container.Nested();
DataSet ds = new DataSet();- เวลาเขียนข้อมูลใน DataSet เป็นไฟล์ XML ใช้คำสั่ง
ds.ReadXml("XmlFile.xml");
ds.WriteXML("XmlFile.xml");- ภายหลังเรียกคำสั่ง ReadXml ถ้ามี table อยู่ก่อนหน้าใน dataset ข้อมูลเก่าจะหาย ดังนั้นหากต้องการอ่านข้อมูลเข้าข้อมูลหลายๆ ตาราง ให้สร้าง DataSet 2 ตัวโดยให้ตัวหนึ่งอ่าน แล้วค่อย copy() table ไปยัง DataSet อีกตัวหนึ่ง
public string GetData(String itemID)2. การใช้คำสั่ง select จะมีรูปแบบเหมือนกับการ filter ข้อมูล ผลลัพธ์ที่ได้จะอยู่ในรูป array ของ DataRow (DataRow[]) Code การทำงานมีดังนี้
{
DataColumn[] keys = new DataColumn[1];
keys[0] = dataSet1.Tables["TableName"].Columns["ColumnName"];
dataSet1.Tables["TableName"].PrimaryKey = keys;
DataRow findRow = dataSet1.Tables["TableName"].Rows.Find(itemId);
if (findRow != null)
{
return findRow["ItemName"].ToString();
}
else
return "";
}
public string GetData(String itemID)
{
DataRow[] findRow = dataSet1.Tables["TableName"].Select("ColumnName=" + itemID);
if(findRow.Length != 0)
{
return findRow[0]["ColumnName"].ToString();
}
else
{
return null;
}
"Unable to convert MySQL date/time value to System.DateTime"ปัญหานี้สามารถแก้ไขโดยเพิ่มข้อความ
Allow Zero Datetime=True
string conStr = "SERVER=" + hn + ";DATABASE=" + db + ";Port=" + pt + ";UID=" + UID + ";PWD=" + PWD + ";Allow Zero Datetime=true;";MySqlConnection conn = new MySqlConnection(conStr);

public partial class Form1 : Form
{
private MySqlConnection conn;
private MySqlDataAdapter adp;
public
Form1()
{
InitializeComponent();
}
private void Form1_Load(object
sender, EventArgs e)
{
conn = new
MySqlConnection("database=test;server=localhost;uid=root;pwd=password");
adp = new MySqlDataAdapter();
adp.SelectCommand = new MySqlCommand("SELECT * FROM
table1", conn);
MySqlCommandBuilder cb = new
MySqlCommandBuilder(adp);
conn.Open();
adp.Fill(dataSet1,
"table1");// ในกรณีที่ไม่ได้สร้าง table ภายใน dataSet1 ตามข้อ 4 ให้เพิ่ม Code นี้ลงไป
DataColumn dc1 = new DataColumn("id", System.Type.GetType("System.Int32"));
DataColumn dc2 = new DataColumn("Name", System.Type.GetType("System.String"));
DataTable tb = new DataTable("NameList");
dataSet1.Tables.Add(tb);
bindingSource1.DataSource = dataSet1;
bindingSource1.DataMember = "table1";
dataGridView1.AutoGenerateColumns = true;}
private void Form1_FormClosed(object sender, FormClosedEventArgs
e)
{
conn.Close();
}
private void dataGridView1_CellEndEdit(object sender,
DataGridViewCellEventArgs e)
{
adp.Update(dataSet1.Tables["table1"]);
}
private void
dataGridView1_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
{
adp.Update(dataSet1.Tables["table1"]);
}
}
เพิ่มเติม ในกรณีที่ต้องการเชื่อมต่อกับ control อื่นๆ เช่น textbox, combobox ให้ใช้ code ดังต่อไปนี้ในส่วนที่จะเชื่อมต่อกับฐานข้อมูล
ในกรณี textbox
textBox1.DataBindings.Add(new Binding("Text", bindingSource1, "id", true));
ในกรณี combobox
comboBox1.DataSource = dataSet1;
comboBox1.DisplayMember = "table1.Name";
comboBox1.DataBindings.Add(new Binding("Text", bindingSource1, "Name"));
UPDATE `joomla`.`jos_users` SET `password` = MD5( 'newpassword' ) WHERE `jos_users`.`username` = 'admin';
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\AppServ\www\guestbook\guestbook_del_confirm.php:1) in C:\AppServ\www\guestbook\guestbook_del_confirm.php on line 2
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\AppServ\www\guestbook\guestbook_del_confirm.php:1) in C:\AppServ\www\guestbook\guestbook_del_confirm.php on line 2
<a href="url_link">link</a>
<input type="button" onclick="window.location.href='url_link'" value="link_text">
net use lpt1: //comname/shareprinter/ Persistent:yes
หมายเหตุ
comname -> ชื่อคอมพิวเตอร์ที่ share เครื่องพิมพ์
ในกรณีที่ไม่ผ่านระบบเครื่องข่ายหมายถึงเครื่องตัวเอง(อาจจะใช้หมายเลข ip:127.0.0.1 แทนก็ได้)
shareprinter -> ชื่อเครื่องพิมพ์ที่ทำ share
using System;
using System.Text;
namespace DemoEsception
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Point A");
try
{
Console.WriteLine("Point B");
// Try to convert wrong format
Console.WriteLine(int.Parse("abc"));
Console.WriteLine("Point C");
}
catch (FormatException e)
{
Console.WriteLine("Catch exception:{0}",e);
}
Console.WriteLine("Point D");
}
catch (Exception e)
{
Console.WriteLine("Outer exception:{0}",e);
}
Console.WriteLine("Point E");
Console.ReadKey();
}
}
} ผลลัพธ์ที่ได้Point A
Point B
Catch exception:System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Int32.Parse(String s) at DemoEsception.Program.Main(String[] args) in D:\Data\Visual Studio 2008\Projects\DemoEsception\DemoEsception\Program.cs:line 17
Point D
Point Eสังเกตว่าใน code นี้เกิดความผิดพลาดขึ้นเมื่อเกิดความพยายามเปลี่ยนตัวอักษร abc ให้เป็นตัวเลขโดยใช้คำสั่ง int.Parse("abc") ซึ่งจะทำให้เกิด FormatException ขึ้น และเมื่อเกิด Exception ขึ้นนั้นโปรแกรมจะข้าม Point C แล้วทำงานในส่วนของ exception แล้วกลับไปทำงานยัง Point D และ Point E จะเห็นว่าโปรแกรมจะไม่เข้าไปดำเนินการ exception ด้านนอกเนื่องจากได้ดำเนินการ FormatException ไปเรียบร้อยแล้วพิจาณา Code ต่อไปนี้เพิ่มเติม
using System;
using System.Text;
namespace DemoEsception
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Point A");
try
{
Console.WriteLine("Point B");
// Try to convert wrong format
Console.WriteLine(int.Parse("abc"));
Console.WriteLine("Point C");
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine("Catch exception:{0}",e);
}
Console.WriteLine("Point D");
}
catch (Exception e)
{
Console.WriteLine("Outer exception:{0}",e);
}
Console.WriteLine("Point E");
Console.ReadKey();
}
}
} ผลลัพธ์ที่ได้Point APoint BOuter exception:System.FormatException: Input string was not in a correct format. at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) at System.Int32.Parse(String s) at DemoEsception.Program.Main(String[] args) in D:\Data\Visual Studio 2008\Projects\DemoEsception\DemoEsception\Program.cs:line 17Point Eจากตัวอย่างข้างต้นได้เปลี่ยนแปลง Exception เป็น IndexOutOfRangeException ซึ่งทำให้เกิด exception ที่ไม่ได้ดักจับไว้ ผลคือ โปรแกรมจะข้ามการดำเนินการ exception ภายในไปยัง exception ภายนอกซึ่งไม่ได้กำหนดชนิดของ exception ไว้จึงทำให้ การดำเนินการใน Point C และ Point D ถูกข้ามไป เมื่อทำงานในส่วน exception เสร็จแล้วโปรแกรมจึงกลับมาดำเนินการใน Point E ต่อไป