我不知道我在这里做错了什么。我试图在主类、SQL 命令参数中调用 class1.cs,但出现错误。我正在从我以前的帖子开始工作,如果有人可以在这里 帮助我,我将不胜感激,在此先感谢..
类.cs
public static OleDbConnection GetConnection()
{
var myCon = new OleDbConnection();
myCon.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\...Database1.mdb";
return myCon;
}
public static void Insert(string id, string agegroup, string gender, string crimoff, string photoa, string cv)
{
var con = GetConnection();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO Table1 (ID, AgeGroup, Gender, CriminalOffence, photo, CV )";
cmd.Parameters.AddWithValue("@ID", id);
cmd.Parameters.AddWithValue("@AgeGroup", agegroup);
cmd.Parameters.AddWithValue("@Gender", gender);
cmd.Parameters.AddWithValue("@CriminalOffence", crimoff);
cmd.Parameters.AddWithValue("@photo", photoa);
cmd.Parameters.AddWithValue("@CV", cv);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
我收到错误的主窗体类...
private void btnInsert_Click(object sender, EventArgs e)
{
Class1 Insert = new Class1();
Insert(textBox1.Text, comboBox1.Text, comboBox2.Text, rBYes.Text, rBNo.Text, // error pointing at Insert line
pictureBox1.Image, richTextBox1.Text);
if (pictureBox1.Image != null)
{
//using MemoryStream:
ms = new MemoryStream();
pictureBox1.Image.Save(ms, ImageFormat.Jpeg);
byte[] photo_aray = new byte[ms.Length];
ms.Position = 0;
ms.Read(photo_aray, 0, photo_aray.Length);
cmd.Parameters.AddWithValue("@photo", photo_aray);
}