C#数据库编程这里出什么问题了,可以调试,不可以运行!
using System;using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string connStr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Master;Data Source = (local) ";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "Select ID,LastName,FirstName,City from student";
SqlDataReader reader = cmd.ExecuteReader();
string output;
while(reader.Read())
{
output = string.Format("ID{0}\t的FirstName{1},LastName{2},Coty{3}", reader.GetString(3), reader.GetString(2), reader.GetString(1), reader.GetString(0));
Console.WriteLine(output);
}
reader.Close();
conn.Close();
}
}
}
追问:还是不行,为什么?我这是连接SQL server 数据库的!
WHY?