当前位置:编程学习 > C#/ASP.NET >>

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?

答案:string connStr = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Master;Data Source = (local) ";
改为

string connStr = "server=.;database=Master;Integrated Security=SSPI;Persist Security Info=False;";

太强了,网吧里面编程!!你牛B啊```

上一个:编程C#好还是JAVA好?听听建议。。。。。。
下一个:用C#编程,两个数,判断两个数的大小,其中不能出现IF 或 SWITCH

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,