日期:2014-05-17  浏览次数:20794 次

老师帮忙看看,自己找不出来哪错了

  private void button4_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string cstr = @"Data Source=.;Initial Catalog=student;Integrated Security=True";
                string paths = openFileDialog1.FileName;
                string[] names = File.ReadAllLines(paths,Encoding.Default);
                string sql = "insert into Score(sno,cno,grade) values('@SNO','@CNO','@GRADE')";
                using (SqlConnection conn = new SqlConnection(cstr))
                {
                    using (SqlCommand cmd = new SqlCommand(sql, conn))
                    {
                        conn.Open();
                        MessageBox.Show("!!!");
                        foreach (string str in names)
                        {
                            string[] arr = str.Split('-');
                            //string SNO = arr[0];
                            //string CNO = arr[1];
                            //string GRADE = arr[2];
                            MessageBox.Show(arr[0]);
                            MessageBox.Show(arr[1]);
                            MessageBox.Show(arr[2]);