我今天参照JackLee的代码写的图片上传,在选择了图片以后出现错误: 其他信息:当传递具有新行的 DataRow 集合时,更新要求有效的 InsertCommand。怎么回事?
  private void button1_Click(object sender, System.EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "*.bmp;*.jpg;*.gif|*.bmp;*.jpg;*.gif;*.jpeg";
            if(ofd.ShowDialog()==DialogResult.OK)
            {
                string filePath = ofd.FileName;
FileInfo imageFile = new FileInfo(filePath);
pictureBox1.Image = Image.FromFile(filePath);
string getAllPhotos = @"select pic from test";
                DataSet ds = new DataSet();
                string sqlConnection1="data source=192.168.1.6;initial catalog=MailManager;integrated security=SSPI;pers" +
                    "ist security info=true;User ID=sa;password=;workstation id=XJ006;packet size=4096";
                sqlDataAdapter1 = new SqlDataAdapter(getAllPhotos,sqlConnection1);
                sqlDataAdapter1.MissingSchemaAction = MissingSchemaAction.AddWithKey;
FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Read);
                byte[] bPhoto= new byte[fs.Length];
                fs.Read(bPhoto, 0, System.Convert.ToInt32(fs.Length));
                fs.Close();
                sqlDataAdapter1.Fill(ds);
                DataRow oneRow = ds.Tables[0].NewRow();
                oneRow["pic"] = bPhoto;
                
                ds.Tables[0].Rows.Add(oneRow);
                sqlDataAdapter1.Update(ds);
    
                MessageBox.Show("图片入库成功!");
            }
        }

 
											





 
	    

