连接 数据库 不上——求搭救

xilinpz 2013-06-19 06:55:43
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Data.Odbc;
using System.Data.OleDb;

using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 实验八
{
public partial class Form1 : Form
{
static string connectionString = @"DNS=Dong;DBQ=H:\school\work\SQL\第08次上机报告\PZdb.mdf";

public Form1()
{
InitializeComponent();
}

private void first_Click(object sender, EventArgs e)
{
OdbcConnection conObj = new OdbcConnection(connectionString);
conObj.Open();

OdbcCommand command = new OdbcCommand("select * form Student",conObj);


OdbcDataReader reader = command.ExecuteReader();

if (reader.Read())
{
information.Text = reader.GetString(0);
information.Text = reader.GetString(1);
information.Text = reader.GetString(2);
information.Text = reader.GetString(3);
information.Text = reader.GetString(4);
}
reader.Close();
conObj.Close();
}

}
}

...全文
71 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xilinpz 2013-06-19
  • 打赏
  • 举报
回复
引用 1 楼 Jia_H 的回复:
那个DNS是在机器上创建的一个东东,换个机器没有对应项或者虽然是名称相同可是实际的链接对象不同也不能成功的。换成显式连接信息。
请问大哥 怎么显示连接呢?
Jia_H 2013-06-19
  • 打赏
  • 举报
回复
那个DNS是在机器上创建的一个东东,换个机器没有对应项或者虽然是名称相同可是实际的链接对象不同也不能成功的。换成显式连接信息。

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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