ฟอร์มอยู่ด้านล่างค่ะ
โค๊ดที่เอามาให้ดูยังไม่มีในส่วนของการแสดงข้อมูลนะค่ะ แค่ลอง 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);
}
}
}