|
 |
|
ขอคำแนะนำ การ Import ไฟล์ Excellหรือ จาก text ลง Data base sql server 2008 ทีครับ |
|
 |
|
|
 |
 |
|
ได้หลายวิธีครับ จะผ่าน ADO.NET ก็ได้ครับ
Code (C#)
OleDbConnection objConn = new OleDbConnection();
OleDbDataAdapter dtAdapter = default(OleDbDataAdapter);
DataTable dt = new DataTable();
string strConnString = null;
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0; " + "Data Source=" + Server.MapPath("MyXls/MyExcelDB.xls") + ";Extended Properties=Excel 8.0;";
objConn = new OleDbConnection(strConnString);
objConn.Open();
string strSQL = null;
strSQL = "SELECT * FROM [Sheet1$]";
dtAdapter = new OleDbDataAdapter(strSQL, objConn);
dtAdapter.Fill(dt);
//*** BindData To DataGrid ***'
this.myDataGrid.DataSource = dt;
this.myDataGrid.DataBind();
dtAdapter = null;
objConn.Close();
objConn = null;
string connetionString = null;
SqlConnection connection = default(SqlConnection);
SqlDataAdapter adapter = new SqlDataAdapter();
int i = 0;
string sql = null;
connetionString = "Data Source=ServerName;Initial Catalog=MyDatabase;User ID=UserName;Password=Password";
connection = new SqlConnection(connetionString);
connection.Open();
for (i = 0; i <= dt.Rows.Count - 1; i++) {
sql = "insert into product (Product_id,Product_name,Product_price) values('" + dt.Rows[i][0] + "','" + dt.Rows[i][1] + "','" + dt.Rows[i][2] + "')";
adapter.InsertCommand = new SqlCommand(sql, connection);
adapter.InsertCommand.ExecuteNonQuery();
}
connection.Close();
Go to : อยากจะทราบวิธีการเอาข้อมูลที่เป็น excel แปลงลง MS SQL Sever 2005 แล้วสร้างฟอร์มในการปริ้น ข้อมูลนั้นออกมาค่ะ
Go to : ASP.NET Import Excel to Database (Excel Application)
Go to : ASP.NET Microsoft SQL Server (System.Data.SqlClient)
Go to : Import data excel to SQL Server 2005 ทำยังไง ช่วยตอบให้ทีนะครับ
|
 |
 |
 |
 |
Date :
2011-12-23 14:13:38 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบพระคุณมากครับ ผมลองหาข้อมูลมีแต่ การ import เข้า ตัว database sql เลย ไม่มีแบบ ทำจาก window from เข้าฐานข้อมูลที่ผมต้องการ ผมขอบคุณพี่วินมากเลยครับที่แนะนำ
|
 |
 |
 |
 |
Date :
2011-12-23 14:21:55 |
By :
patzy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณมากเลยครับ ทำได้แล้วครับ
ขอขอบพระคุณเป็นอย่างสูงครับ ที่ชี้ทางสว่างให้เด็กน้อยตาดำๆ ><
|
 |
 |
 |
 |
Date :
2011-12-23 15:03:03 |
By :
patzy |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|