สอบถามผู้รู้เกี่ยวกับการเรียกใช้ sqlce ใน win app ธรรมดา ได้หรือไม่

Last post 27 Aug 2010 21:59 by abductor. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 21 Aug 2010 16:01

    • abductor
    • Top 50 Contributor
      Female
    • Joined on 21 Aug 2010
    • Samutprakan
    • Posts 9

    สอบถามผู้รู้เกี่ยวกับการเรียกใช้ sqlce ใน win app ธรรมดา ได้หรือไม่

     คือจะลองทำการ บันทึกข้อมูลจาก sql server ไปใส่ไว้ใน sqlce ค่ะ ก็เลยลองทำฟอร์มจำลองใน win app ธรรมดา แล้วให้ทำการเรียกใช้ sqlce ค่ะ แล้วมันเกิด error ว่า

    Unable to load DLL 'sqlceme30.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

    จึงขอสอบถามผู้รู้ค่ะว่า

    เราสามารถเรียกใช้ sqlce ที่หน้าฟอร์มของ win app ธรรมดาได้หรือไม่่ค่ะ

    ถ้าสามารถทำได้ แต่มันฟ้อง error ตามข้างต้น จะแก้ไขได้อย่างไรค่ะ

     

    รบกวนผู้รู้ตอบด้วยค่ะ

  • 26 Aug 2010 9:48 In reply to

    Re: สอบถามผู้รู้เกี่ยวกับการเรียกใช้ sqlce ใน win app ธรรมดา ได้หรือไม่

    เอา Code มาดูหน่อยคับ จะได้ช่วยดู...
  • 27 Aug 2010 8:32 In reply to

    • abductor
    • Top 50 Contributor
      Female
    • Joined on 21 Aug 2010
    • Samutprakan
    • Posts 9

    Re: สอบถามผู้รู้เกี่ยวกับการเรียกใช้ sqlce ใน win app ธรรมดา ได้หรือไม่

    ฟอร์มอยู่ด้านล่างค่ะ

    โค๊ดที่เอามาให้ดูยังไม่มีในส่วนของการแสดงข้อมูลนะค่ะ แค่ลอง connect sqlce ให้ได้ก่อนเฉย ๆ ค่ะ แต่มันก็ connect sqlce ไม่ได้ โดยมันขึ้นฟ้อง error ตามข้างต้นที่ถามค่ะ

    using System;

    using System.Collections.Generic;

    using System.ComponentModel;

    using System.Data;

    using System.Drawing;

    using System.Text;

    using System.Windows.Forms;

    using System.Data.SqlClient;

    using System.Data.SqlServerCe;

     

    namespace copyData

    {

    public partial class Form1 : Form

    {

    public Form1()

    {

    InitializeComponent();

    }

    string strConnSql = "Data Source=NBX;Initial Catalog=bfctest_barcode;Persist Security Info=True;User ID=sa";

    string strConnSdf = "Data Source =C:\\Documents and Settings\\test\\My Documents\\Visual Studio 2005\\Projects\\Stock_WM6_V2\\Stock_WM6_V2\\StockS1.sdf; ";

    SqlConnection objConn;

    SqlCeConnection objCe;

    private void btnSql_Sdf_Click(object sender, EventArgs e)

    {

    objConn = new SqlConnection(strConnSql);

    objConn.Open();

    if (objConn.State == ConnectionState.Open)

    {

    BindData(objConn);

    this.lblText.Text = "Copy Data Complete";

    }

    else

    {

    this.lblText.Text = "SQL Server Connect Failed";

    }

    objConn.Close();

    }

    private void BindData(SqlConnection objConn)

    {

    string strSQL = "";

    if (rdOrderPlan.Checked == true)

    {

    strSQL="select * from tmp_order_plan1";

    }

    else if (rdProPlan.Checked==true)

    {

    strSQL="select * from tmp_pro_plan";

    }else if (rdLocation.Checked==true)

    {

    strSQL = "select * from location_s1";

    }

    //SqlConnection objConn = new SqlConnection();

    SqlCommand objCmd = new SqlCommand();

    SqlDataAdapter dtAdapter = new SqlDataAdapter();

    DataSet ds = new DataSet();

    DataTable dt = new DataTable();

    objCmd.Connection = objConn;

    objCmd.CommandText = strSQL ;

    objCmd.CommandType = CommandType.Text;

    dtAdapter.SelectCommand = objCmd;

    //dtAdapter.Fill(ds);

    dtAdapter.Fill(dt);

    //*** BindData to GridView ***//

    //myGridView.DataSource = ds;

    myGridView.DataSource = dt; //กำหนดให้เป็น table

    //myGridView.DataBind(); <-- เป็นคำสั่งที่ใช้กับ web app

    dtAdapter = null;

    objConn.Close();

    objConn = null;

    if (myGridView.DataSource.Equals(0))

    {

    this.lblTxt2.Text = "Out of Data";

    }

    else

    {

    this.lblTxt2.Text = "Have Data";

    objCe = new SqlCeConnection(strConnSdf);

    objCe.Open();

    if (objCe.State==ConnectionState.Open )

    {

    this.lblTxt3.Text = "connection to ce";

    }

    else

    {

    this.lblTxt3.Text = "CE Connect Failed";

    }

    }

     

    }

    private void Form1_Load(object sender, EventArgs e)

    {

    // TODO: This line of code loads data into the 'bfctest_barcodeDataSet.location_s1' table. You can move, or remove it, as needed.

    this.location_s1TableAdapter.Fill(this.bfctest_barcodeDataSet.location_s1);

    }

    }

    }

     


  • 27 Aug 2010 11:56 In reply to

    Re: สอบถามผู้รู้เกี่ยวกับการเรียกใช้ sqlce ใน win app ธรรมดา ได้หรือไม่

    ดูจาก error แล้วว เหมือน มีปัญหากับ dll..   (เหมือนคนล่ะ version ?)
    ไม่ทราบว่า ตอน Create database CF อ่ะ (.sdf) อ่ะ
    สร้างจาก VS หรือ SQL Managment Studio คับ (CF คนล่ะ  versionป่าวน้าาา)

    ลองดูใน Reference ที่ add เข้ามา มันเป็น dll
    (System.Data.SqlServerCe) มันชี้ไปไหนคับ
    ของผม VS 2008 + CF 3.5 on Win7 x64
    ชี้ไปที่ C:\Program Files (x86)\Microsoft SQL Server Compact Edition\v3.5\Devices\System.Data.SqlServerCe.dll

  • 27 Aug 2010 21:59 In reply to

    • abductor
    • Top 50 Contributor
      Female
    • Joined on 21 Aug 2010
    • Samutprakan
    • Posts 9

    Re: สอบถามผู้รู้เกี่ยวกับการเรียกใช้ sqlce ใน win app ธรรมดา ได้หรือไม่

    ตอน create database sqlce  ทำใน vs2005 ค่ะ ส่วน database sqlserver เป็น sql 2000 ค่ะ แต่ตอนนี้กำลังเปลี่ยนมาลองเล่น VS2008 ค่ะ ถ้ายัง error เหมือนเดิมอยู่ จะมารายงานให้ทราบและมาขอคำชี้แนะเพิ่มเติมนะค่ะ

     

    ขอบคุณมาก ๆ ค่ะ

Page 1 of 1 (5 items)