using System;
using System.Data ;
using System.Data.SqlClient;
namespace DataReaderExample
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{SqlConnection thisConnection=new SqlConnection(@"Data Source=(local);Integrated Security=SSPI;" + "Initial Catalog=northwind");
thisConnection.Open();
SqlCommand thisCommand=thisConnection.CreateCommand();
thisCommand.CommandText="SELECT CustomerID,ComanyName FROM Customers";
SqlDataReader thisReader=thisCommand.ExecuteReader();
while(thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}",
thisReader["CustomerID"],thisReader["CompanyName"]);}
thisReader.Close();
thisConnection.Close(); //
// TODO: 在此处添加代码以启动应用程序
//
}
}
}
帮我看看有错误吗?
using System.Data ;
using System.Data.SqlClient;
namespace DataReaderExample
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{SqlConnection thisConnection=new SqlConnection(@"Data Source=(local);Integrated Security=SSPI;" + "Initial Catalog=northwind");
thisConnection.Open();
SqlCommand thisCommand=thisConnection.CreateCommand();
thisCommand.CommandText="SELECT CustomerID,ComanyName FROM Customers";
SqlDataReader thisReader=thisCommand.ExecuteReader();
while(thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}",
thisReader["CustomerID"],thisReader["CompanyName"]);}
thisReader.Close();
thisConnection.Close(); //
// TODO: 在此处添加代码以启动应用程序
//
}
}
}
帮我看看有错误吗?
解决方案 »
- 点击提交按钮后,为了防止重复点击,如何将这个按钮变灰。
- vs 2008 datagridview 添加一列,包含2个linklabel 怎么写
- C# listview 控件中,以列表呈现,如何获取选中的某一项的名称
- Panel的Scroll事件怎样在结束滚动时触发?
- 操作datagridview数据
- 从字符串转换为datetime 时发生语法错误
- 关于xml远程写操作的结账都为0吗,没有人能有个具体的东西吗
- 我想短期内学会.net,应该如何做呢?
- 打包程序时 添加自动安装数据库
- 为什么我两台电脑互传文件一般只能达到7K??急!
- 熟手一句话就可以帮我解决的问题(关于DATAGRID 右键改变索引)!
- 如何禁止移动用windows.open打开的页面。
thisConnection.Open();
try
{
....
}
finally
{
thisConnection.Close();
}
在thisReader.Read())还没有完成是你就thisReader.Close();在datareader里是不允许的!
你最好try()catch()finally{thisReader.Close();thisConnection.Close(); }
{
MessageBox.show(ex.Tostring());
}