SqlConnection con = new SqlConnection(x)写到excel导入sql这里就是执行不了 估计是x这里的链接字符有问题 请教大家要怎么比较好呢

解决方案 »

  1.   


    SqlConnection con = new SqlConnection("server=.;uid=用户名;pwd=密码;database=数据库名");你这问题和你题目都对不上。。
      

  2.   

    Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\Administrator\\桌面\\11.xls;Extended Properties='Excel 8.0;HDR=NO;IMEX=1就是这个啊 我用桌面的一个文件测试 还是不行
      

  3.   

      //导入excel
            private void button3_Click(object sender, EventArgs e)
            {
                if (MessageBox.Show("导入将直接覆盖以前的数据", "警告", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    if (openFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        if (openFileDialog1.OpenFile() != null)
                        {
                            if (Comm.EduceExcel(openFileDialog1.FileName))
                            {
                                try
                                {
                                    for (int i = 0; i < Comm.Dt.Rows.Count; i++)
                                    {
                                        message ok=new message();
                                        ok.Id = Comm.Dt.Rows[i].ItemArray[0].ToString();
                                        ok.Bianhao = Comm.Dt.Rows[i].ItemArray[1].ToString();
                                        ok.Box = Comm.Dt.Rows[i].ItemArray[2].ToString();
                                        ok.Boxname = Comm.Dt.Rows[i].ItemArray[3].ToString();
                                        ok.Username = Comm.Dt.Rows[i].ItemArray[4].ToString();
                                        DateTime dt = new DateTime();
                                        DateTime.TryParse(Comm.Dt.Rows[i].ItemArray[5].ToString(), out dt);
                                        ok.Date = dt;
                                        b okk = new b(); 
                                        okk.aadd(ok);
                                    }                                getdate();
                                    MessageBox.Show("恭喜,好友信息导入成功!\t\t", "提示");
                                }
                                catch
                                {
                                    MessageBox.Show("对不起,好友信息导入失败!\t\t", "提示");
                                }
                            }
                        }
                    }
      

  4.   

    public bool aadd(message aa)
            {
                using (SqlConnection con = new SqlConnection(a.ee))
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand("INSERT INTO [message](bianhao,box, boxname, username, date VALUES (@bianhao,@box,@boxname,@username,@date)", con);
                    cmd.Parameters.AddWithValue("@bianhao", aa.Bianhao);
                    cmd.Parameters.AddWithValue("@box", aa.Box);
                    cmd.Parameters.AddWithValue("@boxname", aa.Boxname);
                    cmd.Parameters.AddWithValue("@username", aa.Username);
                    cmd.Parameters.AddWithValue("@date", aa.Date);
                    cmd.ExecuteNonQuery();
                    return true;
                    
      

  5.   

    public static readonly string ee =
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Documents and Settings\\Administrator\\桌面\\11.xls;Extended Properties='Excel 8.0;HDR=NO;IMEX=1'";