私は ado.net プロジェクトに取り組んでいます。以前はコード用に別のクラスを持っていましたが、今はローカル データベースについて詳しく学ぼうとしていますが、SQL コマンドを含むクラスを呼び出そうとしたときに在庫がありました。私のコードを見て、在庫のある場所にコメントしました
namespace Maintenance
{
public partial class registerReports : Form
{
private void btnSave_Click(object sender, EventArgs e)
{
//the code works if it exists here
/**
conn.Open();
com.Parameters.AddWithValue("@reportID",
tbReportIDox.Text);
com.ExecuteNonQuery();
conn.Close();
**/
}
}
}
class reportTableSQL
{
public void reportTable()
{
string connectionString = connectionString = "Data Source=
..//..//maintenanceDB.sdf";
SqlCeConnection conn = new SqlCeConnection(connectionString);
using (SqlCeCommand com = new SqlCeCommand("INSERT INTO
ReportForm VALUES(@reportID)", conn))
{
// if i call this method from class registerReports : Form
// it doesn't recognise tbReportIDox.Text as
//it isn't exist in this class
/**
conn.Open();
com.Parameters.AddWithValue("@reportID",
tbReportIDox.Text);
com.ExecuteNonQuery();
conn.Close();
**/
}
}
}
ありがとうございました