WCE 中用c#写的数据库连接怎么不对啊

wangzhenyue 2009-02-10 02:21:16
如题..大家写一个给我个事例..谢谢
...全文
69 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
feishanm 2009-02-11
  • 打赏
  • 举报
回复
先检测一下网络。
  把异常信息弹出来看看。
shigang207 2009-02-11
  • 打赏
  • 举报
回复
我把你的代码考下来,在我的win ce 设备上调试是能连接上数据库的。
建议:
1、检查你的wince设备是否连接在网络上;
2、连接字符串有没有写错。
示例如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DeviceAppText
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("server=192.168.1.100;uid=sa;pwd=1;database=Northwind");
try
{
//出现异常无法连接数据库

SqlCommand com =new SqlCommand("select * from Orders",con);
com.CommandType = CommandType.Text;
con.Open();
SqlDataAdapter dr = new SqlDataAdapter(com);
DataSet ds = new DataSet();
dr.Fill(ds);
//int i = Convert.ToInt32(com.Parameters["@Return"].Direction);
//if (i == 0)
//{
// MessageBox.Show("用户名或密码错误");
//}
//else if (i == 1)
//{
// frmGnxzq objGnxzq = new frmGnxzq();
// this.Hide();
// objGnxzq.Show();
//}
MessageBox.Show(ds.Tables[0].Rows[0][0].ToString());
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
//closesqlconnection();
con.Close();
con.Dispose();
}
}
}
}
wangzhenyue 2009-02-10
  • 打赏
  • 举报
回复
   SqlConnection con = new SqlConnection("server=192.168.15.40;uid=sa;pwd=123456;database=coldSMS");
try
{
con.Open(); //出现异常无法连接数据库
SqlCommand com = con.CreateCommand();
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "logg";
com.Parameters.Add(new SqlParameter("@a", SqlDbType.Int, 4));
com.Parameters["@a"].Value = logname;
com.Parameters.Add(new SqlParameter("@b", SqlDbType.Int, 4));
com.Parameters["@b"].Value = logpwd;
com.Parameters.Add(new SqlParameter("@Return", SqlDbType.Int, 4));
com.Parameters["@Return"].Direction = ParameterDirection.ReturnValue;
com.ExecuteNonQuery();
int i = Convert.ToInt32(com.Parameters["@Return"].Direction);
if (i == 0)
{
MessageBox.Show("用户名或密码错误");
this.txtZh.Text = "";
this.txtMm.Text = "";
this.txtZh.Focus();
}
else if (i == 1)
{
frmGnxzq objGnxzq = new frmGnxzq();
this.Hide();
objGnxzq.Show();
}
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
//closesqlconnection();
con.Close();
con.Dispose();
}
}
91program 2009-02-10
  • 打赏
  • 举报
回复
LZ,如何不对法?
你又是如何连接的?

19,504

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧