请问以下程序哪里错误了,谢了

jenny5466 2003-10-20 07:44:34
using System;
using System.Data;
using System.Data.SqlClient;

namespace DataReaderExample
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: 在此处添加代码以启动应用程序
//

//Specify SQL Server-specific connection string
SqlConnection thisConnection=new SqlConnection("server=172.16.1.98;uid=sa;pwd=;database=Northwind");//SSPI:Security Support Provider Interface

//open connection
thisConnection.Open();

//create SqlCommander for this connection
SqlCommand myCommand=new SqlCommand("SELECT CustomerID,CompanyName from Customers",thisConnection);

//Execute DataReader for specified command
SqlDataReader thisReader=myCommand.ExecuteReader();

//where there are rows to read
while(thisReader.Read())
{
//Output ID and name columns
Console.WriteLine("\t{0}\t{1}",thisReader["CustomerID"],thisReader["CompanyName"]);

}
//close reader
thisReader.Close();

//close connection
thisConnection.Close();
}
}
}
...全文
33 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
xixigongzhu 2003-10-21
  • 打赏
  • 举报
回复
斑竹提出这个问题的原因是什么?就是出了什么错或者问题。
haoliqi 2003-10-20
  • 打赏
  • 举报
回复
是什么错误信息?
hq1305018 2003-10-20
  • 打赏
  • 举报
回复
将代码用Try{}Catch{}包起来,捕获异常。
如果有异常,再贴出来,我帮你分析。
jenny5466 2003-10-20
  • 打赏
  • 举报
回复
SqlCommand myCommand=new SqlCommand("SELECT CustomerID,CompanyName from Customers",thisConnection);
这句错了吗
orcale 2003-10-20
  • 打赏
  • 举报
回复
把你出錯的位置說出來
看程式沒有問題

110,499

社区成员

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

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

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