日期:2014-05-17 浏览次数:21050 次
String connStr = "server='" + SeverName + "';Database='" + DBName + "';uid='" + UserName + "';pwd='" + UserPW + "'"; string sql="select * from t_a"; DataSet dt = new DataSet("t_a");//创建一个数据集dt MySqlConnection Conn = new MySqlConnection(connStr);//定义新的数据连接控件并初始化 Conn.Open();//打开连接 MySqlDataAdapter reads = new MySqlDataAdapter(sql, Conn);//定义并初始化数据适配器 MySqlCommandBuilder cmb = new MySqlCommandBuilder(reads); reads.MissingSchemaAction = MissingSchemaAction.AddWithKey; reads.Fill(dt, "t_a"); //将数据适配器中的数据填充到数据集dt中 FileStream fs = new FileStream(@"E:\My Pictures\test.bmp", FileMode.OpenOrCreate, FileAccess.Read); byte[] MyData = new byte[fs.Length]; fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); DataRow myRow; myRow = dt.Tables["t_a"].NewRow(); myRow["image"] = MyData; dt.Tables["t_a"].Rows.Add(myRow); reads.Update(dt, "t_a"); Conn.Close();//关闭连接
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Dnq???>??8p??&??,?????HV{x???tR {[))???7???|lV?y??|?n??fu??G?Io????? 4?Rup??' at line 1