简体   繁体   中英

argument exception was unhandled in sql connection

I am getting an error when I try to run my program which says -

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.

at using (conn = new SqlConnection(connstring))

the whole code for that -

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;
        }
    }`
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;
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM