c#查询数据库帮助
本文关键字:帮助 数据库 查询 | 更新日期: 2023-09-27 17:49:44
我在这里做一个OCR。在我的系统中,用户输入图像、字符和描述。
如果用户想要输入另一个具有相同字符和描述的图像,用户只需要导入现有的图像,告诉系统字符和描述是相同的,这样用户就不需要再次输入字符和描述。
有人知道怎么做吗?
下面是我的代码:con = new System.Data.SqlClient.SqlConnection();
con.ConnectionString = "Data Source=SHEN-PC''SQLEXPRESS;Initial Catalog=CharacterImage;Integrated Security=True";
con.Open();
//set variables to the textbox.text
String ImageLocation = imgLoc.Text;
String typeName = CharTB.Text;
String ImportExt = importTB.Text;
String CharDesc = DescTB.Text;
String fileName = System.IO.Path.GetFileName(ImageLocation);
String savePath = @"C:'Users'Shen'Desktop'LenzOCR'LenzOCR'WindowsFormsApplication1'ImageFile'" + fileName;
inputImageBox.Image = Image.FromFile(ImageLocation);
inputImageBox.Image.Save(savePath);
String insertData = "INSERT INTO CharacterImage(ImageName, ImagePath, Character, CharacterDescription) VALUES('"+fileName+"', '"+savePath+"', '"+typeName+"', '"+CharDesc+"')";
SqlCommand cmd = new SqlCommand(insertData, con);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Character Inserted", "Insert Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
descDisplayTB.Text = typeName + "'r'n'r'n" + CharDesc;
//set the Textbox to empty and the "Type Character" textboxt to uneditable
//and the "Import" button to unclickable after user add the data into the database
imgLoc.Text = "";
CharTB.Text = "";
importTB.Text = "";
DescTB.Text = "";
CharTB.ReadOnly = true;
ImportButton.Enabled = false;
}
private void button2_Click(object sender, EventArgs e)
{
descDisplayTB.Text = "";
pictureBox1.Image = null;
}
可按以下步骤工作:
- 要求用户输入图像id[可能是浏览或其他内容],其中的详细信息将被复制。
- 从数据库中获取该图像的详细信息
- 在数据库中插入新更新的图像和获取的详细信息。
在输入第一张图像后,我不会清除字符和描述字段。这样,用户只需要选择下一张图片,然后重新提交表单。
我有一个高层次的答案。
我将保留最近识别或加载的数据的集合。然后,当每个项目加载时,您可以创建一个滚动窗口来选择最近上传到数据库的字符图像,因此该人不需要将其与您的训练集重新关联。