当我尝试运行我的程序时出现错误 -
An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll
Additional information: Initialiseringsstrengens format does not match the specification starting at index 0.
在using (conn = new SqlConnection(connstring))
整个代码 -
public partial class MainWindow : Window
{
public SqlConnection conn;
public SqlCommand cmd;
string connstring = (@"Data Source=SINDALSQL\MSSQL14; Initial Catalog=OminiData; Integrated Security =True");
string sql = ("SELECT Mærke, Model, Årgang, [Motor Type], Krydsmål, Centerhul, Møtrik, Bolter, Dæk, Fælge FROM Hjuldata");
private void binddata()
{
DataSet1 ds = new DataSet1();
using (conn = new SqlConnection(connstring))
{
cmd = new SqlCommand(sql, conn);
SqlDataAdapter adp = new SqlDataAdapter();
conn.Open();
adp.SelectCommand = cmd;
adp.Fill(ds, "Hjuldata");
hjuldata.DataContext = ds;
}
}`
答案 0 :(得分:0)
public partial class MainWindow : Window {
public SqlConnection conn;
public SqlCommand cmd;
string connstring = (@"Data Source=SINDALSQL\MSSQL14; Initial Catalog=OminiData; Integrated Security =True");
string sql= ("SELECT Mærke, Model, Årgang, [Motor Type], Krydsmål, Centerhul, Møtrik, Bolter, Dæk, Fælge FROM Hjuldata");
private void binddata() {
DataTable dt = new DataTable();
using (SqlDataAdapter adp = new SqlDataAdapter(sql,connstring)) {
adp.Fill(dt);
hjuldata.DataContext = dt;
}
}
}