【发布时间】:2015-06-03 14:22:41
【问题描述】:
我卡在连接 SQL 并运行一个简单的选择查询,我需要将 select * from ServerInfo where ServerID = 1991638835" 输出到控制台行或 txt 文件:
这是我的代码:
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Text;
namespace ConnectingToSQLC
{
class Program
{
static void Main(string[] args)
{
SqlConnection conn = new SqlConnection("server= XXXXX; database = ES1Archive; Integrated Security=false; User ID = sa; Password=XXXXXX");
conn.Open();
SqlCommand cmd = new SqlCommand("select * from ServerInfo where ServerID = 1991638835", conn);
SqlDataReader reader = cmd.ExecuteReader ();
while (reader.Read())
{
//Console.WriteLine ("{1}", "{0}", reader.GetString (0), reader.GetString (1));
Console.WriteLine(reader.GetString(3));
}
reader.Close();
conn.Close();
if (Debugger.IsAttached)
{
Console.ReadLine();
}
}
}
}
一切正常。但如果我改为
Console.WriteLine ("{1}", "{3}", reader.GetString (1), reader.GetString (3)); 我总是有第 2 列。总共有 7 列,第 3 列是空的,而第 4 列是 XML。
如何修改我的代码以全部转储?
【问题讨论】:
-
表格的格式是什么?