编译的时候这是什么原因 在建立与服务器的连接时出错。在连接到 SQL Server 2005 时,在默认的设置下 SQL Server 不允许进行远程连接可能会导致此失败。 (provider: 命名管道提供程序, error: 40 - 无法打开到 SQL Server 的连接) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 了解字面意思!查看SQL2005有无正常运行!! 没有连接到服务器或者服务器不允许连接。你的帐户权限开了的吗?SQL Server Management Studio Express 在SQL 2005 外围程序里面把 TCP和named打开 sql server2005的问题!!你试试看看能不能连接数据库!! 你把你的连接字符串发出来看看你用SQL Server Management Studio Express-服务器右键属性-安全性-选择sqlserver和windows模式,失败和成功的登录。在选择连接 勾上 允许远程连接此服务器 string Afile = "server=PK-PC;uid=pk;pwd=123456;database=成绩表"; SqlConnection conn = new SqlConnection(Afile); SqlDataAdapter da = new SqlDataAdapter("select 姓名,语文,数学,英语", conn); conn.Open(); DataTable dt = new DataTable(); da.Fill(dt); this.textBox1.Text = dt.Rows[1]["姓名"].ToString(); this.textBox2.Text = dt.Rows[1]["英语"].ToString(); this.textBox3.Text = dt.Rows[1]["语文"].ToString(); this.textBox4.Text = dt.Rows[1]["数学"].ToString(); da.Dispose(); conn.Close(); conn.Dispose(); Data Source=SERVER\SQLSERVER2005;Initial Catalog=数据库;Persist Security Info=True;User ID=sa;PassWord=sa string Afile = "server=PK-PC;uid=pk;pwd=123456;database=成绩表"; //有问题 SqlConnection conn = new SqlConnection(Afile); SqlDataAdapter da = new SqlDataAdapter("select 姓名,语文,数学,英语", conn); //有问题 conn.Open(); DataTable dt = new DataTable(); da.Fill(dt); this.textBox1.Text = dt.Rows[1]["姓名"].ToString(); this.textBox2.Text = dt.Rows[1]["英语"].ToString(); this.textBox3.Text = dt.Rows[1]["语文"].ToString(); this.textBox4.Text = dt.Rows[1]["数学"].ToString(); da.Dispose(); conn.Close(); conn.Dispose();你改成string Afile = "Data Source=服务器名;Initial Catalog=数据库;Persist Security Info=True;User ID=用户名;PassWord=密码";SqlDataAdapter da = new SqlDataAdapter("select 姓名,语文,数学,英语 from 你的表", conn) string Afile = "server=PK-PC;uid=pk;pwd=123456;database=成绩表"; 你把database=成绩表"; 换成database=数据库名; using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Data.SqlClient;using System.Drawing;using System.Text;using System.Windows.Forms;namespace 查询{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button2_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection("server=9aa7107a8cbe4fa;uid=jfq;pwd=123456;database=chengjibiao"); conn.Open(); SqlDataAdapter da = new SqlDataAdapter("select 姓名,数学,英语,语文 from 成绩表", conn); DataTable dt = new DataTable(); da.Fill(dt); this.textBox1.Text = dt.Rows[1]["数学"].ToString(); this.textBox2.Text = dt.Rows[1]["语文"].ToString(); this.textBox3.Text = dt.Rows[1]["姓名"].ToString(); this.textBox4.Text = dt.Rows[1]["英语"].ToString(); da.Dispose(); conn.Close(); conn.Dispose(); } private void button1_Click(object sender, EventArgs e) { } private void textBox2_TextChanged(object sender, EventArgs e) { } }} DataTable dt = new DataTable(); DataSet dt=new DataSet();这样看看 只有数据集dataset才能填充SqlDataAdapter 的对象 多线程下载 有差别吗? 数据库连接问题 Happy 牛 year!~顺便问一个小问题 ArrayList 插入对象 后的访问方法 如何2千万条手机号码快速写入数据库?(C#) C#能不能做个监控IE访问网址的程序 很简单问题! 怎么判断一个应用程序是Web应用程序还是Windows应用程序? .net程序发布,说我的.NetDataOLEDB Provider old…… 泛型问题,求解 这是什么原因,{"从索引 0 处开始,初始化字符串的格式不符合规范。"}
你试试看看能不能连接数据库!!
SqlConnection conn = new SqlConnection(Afile);
SqlDataAdapter da = new SqlDataAdapter("select 姓名,语文,数学,英语", conn);
conn.Open();
DataTable dt = new DataTable();
da.Fill(dt);
this.textBox1.Text = dt.Rows[1]["姓名"].ToString();
this.textBox2.Text = dt.Rows[1]["英语"].ToString();
this.textBox3.Text = dt.Rows[1]["语文"].ToString();
this.textBox4.Text = dt.Rows[1]["数学"].ToString();
da.Dispose();
conn.Close();
conn.Dispose();
SqlConnection conn = new SqlConnection(Afile);
SqlDataAdapter da = new SqlDataAdapter("select 姓名,语文,数学,英语", conn); //有问题
conn.Open();
DataTable dt = new DataTable();
da.Fill(dt);
this.textBox1.Text = dt.Rows[1]["姓名"].ToString();
this.textBox2.Text = dt.Rows[1]["英语"].ToString();
this.textBox3.Text = dt.Rows[1]["语文"].ToString();
this.textBox4.Text = dt.Rows[1]["数学"].ToString();
da.Dispose();
conn.Close();
conn.Dispose();
你改成
string Afile = "Data Source=服务器名;Initial Catalog=数据库;Persist Security Info=True;User ID=用户名;PassWord=密码";SqlDataAdapter da = new SqlDataAdapter("select 姓名,语文,数学,英语 from 你的表", conn)
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 查询
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
} private void button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=9aa7107a8cbe4fa;uid=jfq;pwd=123456;database=chengjibiao");
conn.Open();
SqlDataAdapter da = new SqlDataAdapter("select 姓名,数学,英语,语文 from 成绩表", conn); DataTable dt = new DataTable();
da.Fill(dt);
this.textBox1.Text = dt.Rows[1]["数学"].ToString();
this.textBox2.Text = dt.Rows[1]["语文"].ToString();
this.textBox3.Text = dt.Rows[1]["姓名"].ToString();
this.textBox4.Text = dt.Rows[1]["英语"].ToString();
da.Dispose();
conn.Close();
conn.Dispose();
} private void button1_Click(object sender, EventArgs e)
{
} private void textBox2_TextChanged(object sender, EventArgs e)
{ }
}
}
DataSet dt=new DataSet();
这样看看