我正在从我以前的线程这里工作。我收到这个错误。我不知道如何解决这个问题。我正在尝试在 Main 类中调用 class1.cs。如果有人可以在这里帮助我,将不胜感激。提前致谢...
这是class1.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 photoa)
{
var con = GetConnection();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO Table1 (ID, AgeGroup, Gender, photo )";
cmd.Parameters.AddWithValue("@ID", id);
cmd.Parameters.AddWithValue("@AgeGroup", agegroup);
cmd.Parameters.AddWithValue("@Gender", gender);
cmd.Parameters.AddWithValue("@photo", photoa);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
这是我想称之为的主要课程。
private void btnInsert_Click(object sender, EventArgs e)
{
Class1.Insert(textBox1.Text, comboBox1.Text, comboBox2.Text, pictureBox1.Image); // error is pointing at picture1.Image
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);
}