![](/img/trans.png)
[英]I am getting an object must be marked static error when nothing in my c# program is marked static?
[英]While uploading data to my local database i am getting an error called “Object must implement convertible”
當我嘗試將文件上傳到本地數據庫時,出現錯誤消息“對象必須實現|可轉換”
我真的不知道為什么這樣說。 我需要幫助。
錯誤圖片:
刪除嘗試並捕獲錯誤-https : //imageshack.com/i/kpgFCzkrp
我正在嘗試的代碼:
private void btnUpload_Click(object sender, EventArgs e)
{
try
{
//Throw error if attachment cell is not selected.
//make sure user select only single cell
if (cncInfoDataGridView.SelectedCells.Count == 1 && cncInfoDataGridView.SelectedCells[0].ColumnIndex == 1)
{
UploadAttachment(cncInfoDataGridView.SelectedCells[0]);
}
else
MessageBox.Show("Select a single cell from Attachment column", "Error uploading file", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace, "Error uploading file", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void UploadAttachment(DataGridViewCell dgvCell)
{
using (OpenFileDialog fileDialog = new OpenFileDialog())
{
//Set File dialog properties
fileDialog.CheckFileExists = true;
fileDialog.CheckPathExists = true;
fileDialog.Filter = "All Files|*.*";
fileDialog.Title = "Select a file";
fileDialog.Multiselect = true;
if (fileDialog.ShowDialog() == DialogResult.OK)
{
SqlCeConnection cnn = new SqlCeConnection(Properties.Settings.Default.CncConnectionString);
FileInfo fileInfo = new FileInfo(fileDialog.FileName);
byte[] binaryData = File.ReadAllBytes(fileDialog.FileName);
cncInfoDataGridView.Rows[dgvCell.RowIndex].Cells[1].Value = fileInfo.Name;
SqlCeCommand cmd = new SqlCeCommand("INSERT INTO CncInfo (Drawings) VALUES (@DATA)", cnn);
cmd.Parameters.Add("@DATA", binaryData);
cnn.Open();
cmd.ExecuteNonQuery();
cnn.Close();
}
}
}
當我用以下代碼更新捕獲時。 我收到像這樣的錯誤https://imageshack.com/i/ip6ESuuhp
catch (Exception ex)
{
MessageBox.Show(ex.StackTrace, "Error uploading file", MessageBoxButtons.OK, MessageBoxIcon.Error);
`
完全不推薦使用Add方法,因為它無法以您期望的方式工作。 請執行警告消息告訴您的操作,然后使用AddWithValue 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.