B
Brian Basquille
Hello all,
Bit of a change of pace now. As opposed to the typical questions regarding
my Air Hockey game, am also working on a Photo Album which uses an Access
Database to store information about photos. This information is held inside
the database (photoDB.mdb) in a table called 'photos' - information being
recorded in there are photo information (photoID, location, phDate,
category, caption).
I have inputted my own photos (not via this method) and they all load
correctly. But when adding a new photo, the user needs to clarify if the
photo information is all correct - hence pressing the OK button (see code
below).
I, however, get a 'no value given for one or more required parameters' error
below. Anyone care to share where i've gone wrong? Also, it's hard to know
if this is more relevent in the CSharp newsgroup or the Access / SQL
newsgroup.
Thanks in advance.
PS - just to cover every area, the data types in Access database are as
follows: photoID (Text), location (Text), phDate (Date/Time), category
(Text), caption (Text)
----------------------------------------------------------------------------------------
private void btnOK_Click(object sender, System.EventArgs e)
{
try
{
newPhotoID = lblPhotoID.Text;
newLocation = newFileName.ToString();
newDate = DateTime.Now.Date;
newCategory = cboCategory.Text;
newCaption = txtCaption.Text;
string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "
+System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
+ @"\photoDB.MDB";
string strSQL = "INSERT INTO photos (photoID, location, phDate,
category, caption) VALUES (newPhotoID, newLocation, newDate, newCategory,
newCaption);" ;
// create Objects of ADOConnection and ADOCommand
OleDbConnection myConn = new OleDbConnection(strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, myConn );
myConn.Open();
myCmd.ExecuteNonQuery();
myConn.Close();
}
catch (OleDbException ex)
{
MessageBox.Show("" + ex.Message);
}
}
Bit of a change of pace now. As opposed to the typical questions regarding
my Air Hockey game, am also working on a Photo Album which uses an Access
Database to store information about photos. This information is held inside
the database (photoDB.mdb) in a table called 'photos' - information being
recorded in there are photo information (photoID, location, phDate,
category, caption).
I have inputted my own photos (not via this method) and they all load
correctly. But when adding a new photo, the user needs to clarify if the
photo information is all correct - hence pressing the OK button (see code
below).
I, however, get a 'no value given for one or more required parameters' error
below. Anyone care to share where i've gone wrong? Also, it's hard to know
if this is more relevent in the CSharp newsgroup or the Access / SQL
newsgroup.
Thanks in advance.
PS - just to cover every area, the data types in Access database are as
follows: photoID (Text), location (Text), phDate (Date/Time), category
(Text), caption (Text)
----------------------------------------------------------------------------------------
private void btnOK_Click(object sender, System.EventArgs e)
{
try
{
newPhotoID = lblPhotoID.Text;
newLocation = newFileName.ToString();
newDate = DateTime.Now.Date;
newCategory = cboCategory.Text;
newCaption = txtCaption.Text;
string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= "
+System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)
+ @"\photoDB.MDB";
string strSQL = "INSERT INTO photos (photoID, location, phDate,
category, caption) VALUES (newPhotoID, newLocation, newDate, newCategory,
newCaption);" ;
// create Objects of ADOConnection and ADOCommand
OleDbConnection myConn = new OleDbConnection(strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, myConn );
myConn.Open();
myCmd.ExecuteNonQuery();
myConn.Close();
}
catch (OleDbException ex)
{
MessageBox.Show("" + ex.Message);
}
}