无法将类型“System.Data.SqlClient.SqlCommand”隐式转换为“System.Data.SqlClient.SqlConnection
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSy...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ADO汇总
{
class Program
{
static void Main(string[] args)
{
string dataDir = AppDomain.CurrentDomain.BaseDirectory;
if (dataDir.EndsWith(@"\bin\Debug\")
|| dataDir.EndsWith(@"\bin\Release\"))
{
dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
}
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyData1.mdf;Integrated Security=True;User Instance=True"))
{
conn.Open();
using (SqlConnection cmd = conn.CreateCommand())
{
//我还没有开始写他就报这个错了,另外我创建的cmd. 里面有值,但没有Command。求助。。。
}
}
Console.WriteLine("okay!!!!!!!!!");
Console.ReadKey();
}
}
}
法将类型“System.Data.SqlClient.SqlCommand”隐式转换为“System.Data.SqlClient.SqlConnection 展开
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace ADO汇总
{
class Program
{
static void Main(string[] args)
{
string dataDir = AppDomain.CurrentDomain.BaseDirectory;
if (dataDir.EndsWith(@"\bin\Debug\")
|| dataDir.EndsWith(@"\bin\Release\"))
{
dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName;
AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
}
using (SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyData1.mdf;Integrated Security=True;User Instance=True"))
{
conn.Open();
using (SqlConnection cmd = conn.CreateCommand())
{
//我还没有开始写他就报这个错了,另外我创建的cmd. 里面有值,但没有Command。求助。。。
}
}
Console.WriteLine("okay!!!!!!!!!");
Console.ReadKey();
}
}
}
法将类型“System.Data.SqlClient.SqlCommand”隐式转换为“System.Data.SqlClient.SqlConnection 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询