private void button5_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { if (dataGridView1.SelectedRows[0].Tag != "") { UpdateVersionobj versionobj = dataGridView1.SelectedRows[0].Tag as UpdateVersionobj; //if (MessageBox.Show("确定要上传更新包吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) //{ Cursor.Current = Cursors.WaitCursor; OpenFileDialog filename = new OpenFileDialog(); filename.InitialDirectory = Application.StartupPath; filename.Filter = "压缩文件|*.zip"; filename.RestoreDirectory = true; if (filename.ShowDialog() == DialogResult.OK) { string path = filename.FileName.ToString(); //string name = path.Substring(path.LastIndexOf("\\")+1); //保存文件到SQL Server数据库中 FileInfo fi = new FileInfo(path); FileStream fs = fi.OpenRead(); byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, Convert.ToInt32(fs.Length)); DateLogic dg = new DateLogic(); SqlConnection con = dg.getconn(); SqlCommand cm = new SqlCommand("update updateversion set updateprogram =@updateprogram,updatetime=@updatetime where id=@id", con); SqlParameter spFile = new SqlParameter("@updateprogram", SqlDbType.Image); SqlParameter spupdatetime = new SqlParameter("@updatetime", SqlDbType.Char); SqlParameter spid = new SqlParameter("@id", SqlDbType.Char); spFile.Value = bytes; spupdatetime.Value = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); spid.Value = versionobj.id; cm.Parameters.Add(spFile); cm.Parameters.Add(spupdatetime); cm.Parameters.Add(spid); cm.ExecuteNonQuery(); RefreshRecordList(); } //} } } else { MessageBox.Show("请选择要上传的版本!", "系统提示"); } }