 |
|
มีปัญหาเรื่องการสร้าง VB.NET เกี่ยวกับ Dataset ครับ |
|
 |
|
|
 |
 |
|
ไม่ error แค่นั้นหรอกครับ ลอง build ดู error อีกบาน
การสร้างข้อมูลให้ DataTable (C#)
String[] _DayOfWeek = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
DataTable Dt = new DataTable();
//add columns to datatable
Dt.Columns.Add(new DataColumn("ID", Type.GetType("System.Int16")));
Dt.Columns.Add(new DataColumn("DayOfWeek", Type.GetType("System.String")));
//add rows to datatable
for (int i = 0; i < 7; i++)
{
DataRow Dr = Dt.NewRow();
Dr["ID"] = i + 1;
Dr["DayOfWeek"] = _DayOfWeek[i];
Dt.Rows.Add(Dr);
}
การสร้างข้อมูลให้ DataTable (VB.NET)
Dim _DayOfWeek() As String = New String() { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }
Dim Dt As DataTable = New DataTable()
'add columns to datatable
Dim Column1 As DataColumn = New DataColumn()
Column1.ColumnName = "ID"
Column1.DataType = Type.GetType("System.Int16")
Dim Column2 As DataColumn = New DataColumn()
Column2.ColumnName = "DayOfWeek"
Column2.DataType = Type.GetType("System.String")
Dt.Columns.Add(Column1)
Dt.Columns.Add(Column2)
'add rows to datatable
Dim i As Integer
For i = 0 To 6
Dim Dr As DataRow = Dt.NewRow();
Dr("ID") = i + 1;
Dr("DayOfWeek") = _DayOfWeek(i);
Dt.Rows.Add(Dr);
Next i
|
 |
 |
 |
 |
Date :
2010-01-07 09:56:37 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วถ้าผมต้องการทำเป็น DataSet แล้วตั้งชื่อให้มันอะครับ ต้องพิมพ์ยังไงหรอครับ
|
 |
 |
 |
 |
Date :
2010-01-07 13:40:43 |
By :
Nameless |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (C#)
String[] _DayOfWeek = new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
DataTable Dt = new DataTable();
Dt.TableName = "Mytable"; //เพิ่มบรรทัดนี้
//add columns to datatable
Dt.Columns.Add(new DataColumn("ID", Type.GetType("System.Int16")));
Dt.Columns.Add(new DataColumn("DayOfWeek", Type.GetType("System.String")));
//add rows to datatable
for (int i = 0; i < 7; i++)
{
DataRow Dr = Dt.NewRow();
Dr["ID"] = i + 1;
Dr["DayOfWeek"] = _DayOfWeek[i];
Dt.Rows.Add(Dr);
}
DataSet Ds = new DataSet(); //เพิ่มบรรทัดนี้
Ds.Tables.Add(Dt); //เพิ่มบรรทัดนี้
Code (VB.NET)
Dim _DayOfWeek() As String = New String() { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }
Dim Dt As DataTable = New DataTable()
Dt.TableName = "Mytable" 'เพิ่มบรรทัดนี้
'add columns to datatable
Dim Column1 As DataColumn = New DataColumn()
Column1.ColumnName = "ID"
Column1.DataType = Type.GetType("System.Int16")
Dim Column2 As DataColumn = New DataColumn()
Column2.ColumnName = "DayOfWeek"
Column2.DataType = Type.GetType("System.String")
Dt.Columns.Add(Column1)
Dt.Columns.Add(Column2)
'add rows to datatable
Dim i As Integer
For i = 0 To 6
Dim Dr As DataRow = Dt.NewRow();
Dr("ID") = i + 1;
Dr("DayOfWeek") = _DayOfWeek(i);
Dt.Rows.Add(Dr);
Next i
Dim Ds As DataSet = New DataSet() 'เพิ่มบรรทัดนี้
Ds.Tables.Add(Dt); 'เพิ่มบรรทัดนี้
|
 |
 |
 |
 |
Date :
2010-01-07 14:30:33 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณพี่ tungman มากครับ ตอบเร็วทันใจอีกแว้วววววว
ว่าแต่ทำไมต้องเป็น
Column1.DataType = Type.GetType("System.Int16")
เป็น
Column1.DataType = Type.GetType("Int16") เลยไม่ได้หรอครับ ทำไมต้องมี System ด้วยอะครับ
|
 |
 |
 |
 |
Date :
2010-01-07 22:42:59 |
By :
Nameless |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ถ้าไม่ error ใช้อันไหนก็ได้ครับ
|
 |
 |
 |
 |
Date :
2010-01-08 08:47:28 |
By :
tungman |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แล้วถ้าต้องการไม่ให้คอลัมน์ใน DataGrid ไม่สามารถทำงานได้
|
 |
 |
 |
 |
Date :
2017-08-20 11:27:19 |
By :
ken |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|