2677|4

63

帖子

0

TA的资源

一粒金砂(初级)

楼主
 

WCE 中用c#写的数据库连接怎么不对啊 [复制链接]

如题..大家写一个给我个事例..谢谢

最新回复

先检测一下网络。   把异常信息弹出来看看。  详情 回复 发表于 2009-2-11 21:13
点赞 关注
 

回复
举报

73

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
LZ,如何不对法?
你又是如何连接的?
 
 

回复

74

帖子

0

TA的资源

一粒金砂(初级)

板凳
 
  1.    SqlConnection con = new SqlConnection("server=192.168.15.40;uid=sa;pwd=123456;database=coldSMS");
  2.                 try
  3.                 {
  4.                     con.Open();  //出现异常无法连接数据库
  5.                     SqlCommand com = con.CreateCommand();
  6.                     com.CommandType = CommandType.StoredProcedure;
  7.                     com.CommandText = "logg";
  8.                     com.Parameters.Add(new SqlParameter("@a", SqlDbType.Int, 4));
  9.                     com.Parameters["@a"].Value = logname;
  10.                     com.Parameters.Add(new SqlParameter("@b", SqlDbType.Int, 4));
  11.                     com.Parameters["@b"].Value = logpwd;
  12.                     com.Parameters.Add(new SqlParameter("@Return", SqlDbType.Int, 4));
  13.                     com.Parameters["@Return"].Direction = ParameterDirection.ReturnValue;
  14.                     com.ExecuteNonQuery();
  15.                     int i = Convert.ToInt32(com.Parameters["@Return"].Direction);
  16.                     if (i == 0)
  17.                     {
  18.                         MessageBox.Show("用户名或密码错误");
  19.                         this.txtZh.Text = "";
  20.                         this.txtMm.Text = "";
  21.                         this.txtZh.Focus();
  22.                     }
  23.                     else if (i == 1)
  24.                     {
  25.                         frmGnxzq objGnxzq = new frmGnxzq();
  26.                         this.Hide();
  27.                         objGnxzq.Show();
  28.                     }
  29.                 }
  30.                 catch (SqlException ex)
  31.                 {
  32.                     MessageBox.Show(ex.Message);
  33.                 }
  34.                 finally
  35.                 {
  36.                     //closesqlconnection();
  37.                     con.Close();
  38.                     con.Dispose();
  39.                 }
  40.             }
复制代码
 
 
 

回复

73

帖子

0

TA的资源

一粒金砂(初级)

4
 
我把你的代码考下来,在我的win ce 设备上调试是能连接上数据库的。
建议:
1、检查你的wince设备是否连接在网络上;
2、连接字符串有没有写错。
示例如下:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.Common;
  6. using System.Data.SqlClient;
  7. using System.Drawing;
  8. using System.Text;
  9. using System.Windows.Forms;

  10. namespace DeviceAppText
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         public Form1()
  15.         {
  16.             InitializeComponent();
  17.         }

  18.         private void button1_Click(object sender, EventArgs e)
  19.         {
  20.             SqlConnection con = new SqlConnection("server=192.168.1.100;uid=sa;pwd=1;database=Northwind");
  21.             try
  22.             {
  23.                   //出现异常无法连接数据库
  24.                
  25.                 SqlCommand com =new SqlCommand("select * from Orders",con);
  26.                 com.CommandType = CommandType.Text;
  27.                 con.Open();
  28.                 SqlDataAdapter dr = new SqlDataAdapter(com);
  29.                 DataSet ds = new DataSet();
  30.                 dr.Fill(ds);
  31.                 //int i = Convert.ToInt32(com.Parameters["@Return"].Direction);
  32.                 //if (i == 0)
  33.                 //{
  34.                 //    MessageBox.Show("用户名或密码错误");
  35.                 //}
  36.                 //else if (i == 1)
  37.                 //{
  38.                 //    frmGnxzq objGnxzq = new frmGnxzq();
  39.                 //    this.Hide();
  40.                 //    objGnxzq.Show();
  41.                 //}
  42.                 MessageBox.Show(ds.Tables[0].Rows[0][0].ToString());
  43.             }
  44.             catch (SqlException ex)
  45.             {
  46.                 MessageBox.Show(ex.Message);
  47.             }
  48.             finally
  49.             {
  50.                 //closesqlconnection();
  51.                 con.Close();
  52.                 con.Dispose();
  53.             }
  54.         }
  55.     }
  56. }
复制代码
 
 
 

回复

73

帖子

0

TA的资源

一粒金砂(初级)

5
 
先检测一下网络。
  把异常信息弹出来看看。
 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条
Microchip 直播|利用motorBench开发套件高效开发电机磁场定向控制方案 报名中!
直播主题:利用motorBench开发套件高效开发电机磁场定向控制方案
直播时间:2025年3月25日(星期二)上午10:30-11:30
快来报名!

查看 »

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表