omini data omini data - 7 months ago 20
SQL Question

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

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