 |
|
database ทีมีอยู่ sql server 2005 ให้เป็น xml อย่างไรครับ รบกวนหน่อยครับ การทำ database เป็น xml ต้องทำอย่างไรครับ ช่วยหน่อยนะครับ |
|
 |
|
|
 |
 |
|
Code (VB.NET)
Dim objConn As New SqlConnection
Dim objCmd As New SqlCommand
Dim dtAdapter As New SqlDataAdapter
Dim ds As New DataSet
Dim strConnString,strSQL As String
strConnString = "Server=localhost;Uid=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
strSQL = "SELECT * FROM customer"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
'*** Export XML ***'
ds.Tables(0).WriteXML("C:\XML\myXml.xml")
'ds.Tables(0).WriteXmlSchema("C:\XML\myXml.xml")
ds = Nothing
Code (C#)
SqlConnection objConn = new SqlConnection();
SqlCommand objCmd = new SqlCommand();
SqlDataAdapter dtAdapter = new SqlDataAdapter();
DataSet ds = new DataSet();
string strConnString = null;
string strSQL = null;
strConnString = "Server=localhost;Uid=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
strSQL = "SELECT * FROM customer";
objConn.ConnectionString = strConnString;
var _with1 = objCmd;
_with1.Connection = objConn;
_with1.CommandText = strSQL;
_with1.CommandType = CommandType.Text;
dtAdapter.SelectCommand = objCmd;
dtAdapter.Fill(ds);
dtAdapter = null;
objConn.Close();
objConn = null;
//*** Export XML ***'
ds.Tables[0].WriteXml("C:\\XML\\myXml.xml");
//ds.Tables(0).WriteXmlSchema("C:\XML\myXml.xml")
ds = null;
|
 |
 |
 |
 |
Date :
2011-09-09 08:56:53 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
mr.win ครับ แล้วผมต้องไปเขียนที่ไหนครับ file xml นะครับ ผมดูแล้ว
และ ผมต้องสร้าง ds.Tables[0].WriteXml("C:\\XML\\myXml.xml"); นี้ก่อน หรือยังไงครับ พออธิบายให้ได้หรือป่าวครับ
พอจะมีตัวอย่างการทำหรือป่าวครับ ช่วยหน่อยนะครับ ผมหัดทำนะครับ
|
 |
 |
 |
 |
Date :
2011-09-09 09:31:24 |
By :
jackDr |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันจะสร้างให้เองครับ
ตัวนี้มันไม่ใช่ตัวอย่างเหรอครับ
|
 |
 |
 |
 |
Date :
2011-09-09 09:40:07 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากครับ
ขอโทษนะครับ ขอถามหน่อยครับ แล้วผมต้องเขียน xml ที่ไหนครับ เขียนที่ ฟอร์มไหนครับ ช่วยบอกหน่อยครับ
|
 |
 |
 |
 |
Date :
2011-09-09 10:47:48 |
By :
jackDr |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
และอันนี้อีกอันครับ นี้คือ code Add ลง ฐานข้อมูลนะครับ ไม่รู้ว่าทำไมมันไม่ลงครับ ไปเปิดในฐานข้อมูลไม่มีข้อมูลเลยครับ
Code (C#)
private void insertdata()
{
SqlCeConnection myConnection = default(SqlCeConnection);
myConnection = new SqlCeConnection("Data Source =" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\DB_REST.sdf;"));
myConnection.Open();
SqlCeCommand myCommand = myConnection.CreateCommand();
myCommand.CommandText = "INSERT INTO [Orders] ([Order_Id], [Order_date], [Order_money], [Table_Id], [Order_time] ) VALUES " + " ('" + this.txtOrderNum.Text + "','" + this.txtDate.Text + "','" + this.txtSumPrice.Text + "','" + this.txtTable.Text + "','" + this.txtTime.Text + "' ) ";
myCommand.CommandType = CommandType.Text;
myCommand.ExecuteNonQuery();
for (int i = 0; i < dt.Rows.Count - 1; i++)
{
String OrderId = txtOrderNum.Text;
String qty = dataGrid2[dataGrid2.CurrentCell.RowNumber, 3].ToString();
String FoodID = dataGrid2[dataGrid2.CurrentCell.RowNumber, 0].ToString();
//SqlCeCommand myCommand = myConnection.CreateCommand();
myCommand.CommandText = "INSERT INTO [Order_Detail] ([Order_Id], [QTY], [Food_Id] ) VALUES " + " ('" + OrderId + "','" + qty + "','" + FoodID + "') ";
myCommand.CommandType = CommandType.Text;
myCommand.ExecuteNonQuery();
myConnection.Close();
}
MessageBox.Show("Save Successfully");
}
|
 |
 |
 |
 |
Date :
2011-09-09 10:49:42 |
By :
jackDr |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|