llscwyslm? 2019-05-21 15:24 采纳率: 50%
浏览 380
已采纳

数据库的连接,照书上的代码写的,没法显示前两行,一直显示‘关键字Table’附近有语法错误

图片说明图片说明

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A006
{
public class ExecuteNonQueryExample
{
public static void Main()
{
string str = "Data Source=(local);Initial Catalog=Student1;Integrated Security=True;Pooling=False";
SqlConnection conn = new SqlConnection(str);
string SQLstr = "select top 1 * from Table";
SqlCommand comm = new SqlCommand(SQLstr, conn);
SqlDataReader rd;
try
{
conn.Open();
rd = comm.ExecuteReader();
while (rd.Read())
{
Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", rd["StudentID"].ToString(), rd["XueHao"], rd[2], rd[3], rd[4], rd[5]);
}
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
conn.Close();
}
}
}
}

  • 写回答

3条回答 默认 最新

  • threenewbee 2019-05-21 15:30
    关注
    select * from [table]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services