日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁 > 芯聞號 > 充電吧
[導(dǎo)讀]?private SqlCeConnection OpenSQLCE()? ? ? ? {? ? ? ? ? ? //存取數(shù)據(jù)庫? ? ? ? ? ? //連接sql server Mobile數(shù)據(jù)庫


?private SqlCeConnection OpenSQLCE()
? ? ? ? {
? ? ? ? ? ? //存取數(shù)據(jù)庫
? ? ? ? ? ? //連接sql server Mobile數(shù)據(jù)庫的連接字符串
? ? ? ? ? ? string connString = "Data Source='singleinfo.sdf';Password=";
? ? ? ? ? ? SqlCeEngine engine = new SqlCeEngine(connString);

? ? ? ? ? ? //建立鏈接
? ? ? ? ? ? SqlCeConnection ConnMobile = new SqlCeConnection(connString);
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? ConnMobile.Open();
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception ex)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("不能正確連接數(shù)據(jù)庫!" + ex.Message);
? ? ? ? ? ? ? ? this.Close();
? ? ? ? ? ? ? ? throw;
? ? ? ? ? ? }
? ? ? ? ? ? return ConnMobile;

? ? ? ? }



//**********************************************

?//統(tǒng)計表中的數(shù)據(jù)元組總數(shù)
? ? ? ? ? ? string Strnum = "select count(*) from SingleDatas where Commandeco is not null";
? ? ? ? ? ? SqlCeCommand CommandNum = new SqlCeCommand(Strnum, ConnMobile);
? ? ? ? ? ? string TotalLine = CommandNum.ExecuteScalar().ToString();
? ? ? ? ? ? labelNum.Text = Convert.ToString(TotalLine); ? ?// 顯示數(shù)據(jù)記錄總數(shù) ? ? ?
? ? ? ? ? ? int b = Convert.ToInt32(TotalLine);
? ? ? ? ? ? if (0 == b)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? tableRow = b + 1; ? ? ? ? ? ? ? ?
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //獲取最大的Commandeco值
? ? ? ? ? ? ? ? string strcmd = "Select max(Commandeco) from SingleDatas";
? ? ? ? ? ? ? ? SqlCeCommand commd = new SqlCeCommand(strcmd, ConnMobile);
? ? ? ? ? ? ? ? string A = commd.ExecuteScalar().ToString();
? ? ? ? ? ? ? ? tableRow = Convert.ToInt32(A) + 1; ? ? ? ? ? ? ??
? ? ? ? ? ? }


? ? ? ? ? ? //MessageBox.Show("插入第一條數(shù)據(jù):" + tableRow.ToString()); ?
? ? ? ? ? ? string sql = "Insert into SingleDatas (Commandeco,Tosend,Received) values (" + tableRow + ",'" + Convert.ToString(sendmsg.Text) + "','" + Convert.ToString(recmsg.Text) + "')";
? ? ? ? ? ? SqlCeCommand command = new SqlCeCommand(sql, ConnMobile);
? ? ? ? ? ?
? ? ? ? ? ? int r = command.ExecuteNonQuery(); ?//插入數(shù)據(jù)影響行 ? ?
? ? ? ? ? ? if (r > 0)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("添加數(shù)據(jù)成功!");
? ? ? ? ? ? } ?
? ? ? ? ? ??

///******************************************************

?//在DataGrid1顯示數(shù)據(jù)
? ? ? ? ? ? string str = "select * from SingleDatas";
? ? ? ? ? ? DataSet dataset = new DataSet();
? ? ? ? ? ? SqlCeDataAdapter adapter = new SqlCeDataAdapter(str, ConnMobile);
? ? ? ? ? ? try
? ? ? ? ? ? {
? ? ? ? ? ? ? ? adapter.Fill(dataset, "SingleDatas");
? ? ? ? ? ? ? ? dataGrid1.DataSource = dataset.Tables["SingleDatas"];
? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception ex)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? MessageBox.Show("出錯信息" + ex.Message);
? ? ? ? ? ? ? ? this.Close();
? ? ? ? ? ? ? ? throw;
? ? ? ? ? ? }
? ? ? ? ? ? ConnMobile.Close();


//****************************************************

?SqlCeConnection connMbile = OpenSQLCE();
? ? ? ? ? ? try
? ? ? ? ? ? {


? ? ? ? ? ? ? ? //獲取當(dāng)前選中行的ID值。?
? ? ? ? ? ? ? ? string myID = this.dataGrid1[dataGrid1.CurrentCell.RowNumber, 2].ToString().Trim();

? ? ? ? ? ? ? ? MessageBox.Show("你將刪除第" + myID + "元組");
? ? ? ? ? ? ? ? // string MyDelete = "Delete from SingleDatas where Commandeco=" + dataGrid1.CurrentCell.RowNumber; ? //刪除當(dāng)前選中的行數(shù)的

? ? ? ? ? ? ? ? string MyDelete = "Delete from SingleDatas where Commandeco=" + Convert.ToInt32(myID);
? ? ? ? ? ? ? ? SqlCeCommand MyCommand = new SqlCeCommand(MyDelete, connMbile);
? ? ? ? ? ? ? ? MyCommand.ExecuteNonQuery();

? ? ? ? ? ? }
? ? ? ? ? ? catch (Exception ex)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.WriteLine("{0} Exception caught.", ex);
? ? ? ? ? ? }


本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉