private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename="c:\users\skofiar\documents\visual studio 2013\Projects\Diploma_Project\Diploma_Project\STD_IBU.mdf";Integrated Security=True;Connect Timeout=30");
SqlDataAdapter sda = new SqlDataAdapter(@"SELECT Student_ID, Name, Course_ID, Course_Name, Study_Program FROM Students CROSS JOIN StudentCourse", con);
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
这部分代码显示错误:
c:\ users \ skofiar \ documents \ visual studio 2013 \ Projects \ Diploma_Project \ Diploma_Project \ STD_IBU.mdf“; Integrated Security = True; Connect Timeout = 30”);
之后出现此错误
System.Data.dll中出现未处理的“System.ArgumentException”类型异常
附加信息:初始化字符串的格式不符合从索引28开始的规范。
答案 0 :(得分:1)
看起来文件夹名称周围的双引号导致了问题。您在数据源打开它们,它们在文件夹名称处关闭它们。我会首先尝试删除文件名周围的双引号,我不认为它们在连接字符串中是必需的。
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=c:\users\skofiar\documents\visual studio 2013\Projects\Diploma_Project\Diploma_Project\STD_IBU.mdf;Integrated Security=True;Connect Timeout=30");