在控制台下写程序可以联接到SQL数据库,但不知道怎么在UI下面怎么设置?用什么控件。下面的程序是我在控制台下写的能联接到数据库,但在UI下用datagrid联接不到SQL server ,这是为什么?怎么解决?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,CompanyName from Customers"; SqlDataReader thisReader = thisCommand.ExecuteReader(); while (thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}", thisReader["CustomerId"], thisReader["CompanyName"]);
} thisReader.Close(); thisConnection.Close();
}
{
SqlConnection thisConnection=new SqlConnection(
@"Data Source=(local);Integrated Security=SSPI;"
+"Initial Catalog=northwind"); thisConnection.Open(); SqlCommand thisCommand = thisConnection .CreateCommand();
thisCommand.CommandText="select customerID,CompanyName from Customers"; SqlDataReader thisReader = thisCommand.ExecuteReader(); while (thisReader.Read())
{
Console.WriteLine("\t{0}\t{1}", thisReader["CustomerId"], thisReader["CompanyName"]);
} thisReader.Close(); thisConnection.Close();
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货