I have a form that displays a datagridview via a DataTable. I have a button that opens a new form (EditTask), and it edits the data inside one of my tables in my ms-access database. Whenever I click the "addtask" button inside my EditTask form, my whole applications closes and I do not get any error messages. Here is my code for the save button:
private void btnAddTask_Click(object sender, EventArgs e)
{
ConnectToDataBase();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
RefreshDBConnection();
//Saving 10C Club
if (cboWebsite.Text == "10C CLUB")
{
string query = "UPDATE INTO Tasks SET [PLATFORM]=@platform, [TASK TYPE]=@tasktype, [KEYWORD]=@keyword, [LINK]=@link, [PROFILE]=@profile, [10C EMAIL]=@10email, [10C PASSWORD]=@10pass, where id=@id";
command.Parameters.AddWithValue("@platform", cboWebsite.Text);
if (radio10cDirectLink.Checked == true)
{
command.Parameters.AddWithValue("@tasktype", "Direct Link");
}
else
{
command.Parameters.AddWithValue("@tasktype", "Keyword");
}
if (txt10cKeyword.Text == "ROME")
{
command.Parameters.AddWithValue("@keyword", "");
}
else
{
command.Parameters.AddWithValue("@keyword", txt10cKeyword.Text);
}
if (radio10cDirectLink.Checked == true)
{
command.Parameters.AddWithValue("@link", txt10cDirectLink.Text);
}
else
{
command.Parameters.AddWithValue("@link", txt10cHomePage.Text);
}
command.Parameters.AddWithValue("@profile", cboProfiles.Text);
command.Parameters.AddWithValue("@10email", txt10cLoginEmail.Text);
command.Parameters.AddWithValue("@10pass", txt10cLoginPassword.Text);
command.Parameters.AddWithValue("@ID", txtID.Text);
command.CommandText = query;
command.ExecuteNonQuery();
RefreshDBConnection();
connection.Close();
MessageBox.Show("Task Edited");
this.Close();
}
if (cboWebsite.Text == "DRY GOODS")
{
string query = "UPDATE INTO Tasks SET [PLATFORM]=@platform, [TASK TYPE]=@tasktype, [KEYWORD]=@keyword, [LINK]=@link, [PROFILE]=@profile, [10C EMAIL]=@10email, [10C PASSWORD]=@10pass, where id=@id";
command.Parameters.AddWithValue("@platform", cboWebsite.Text);
if (radioDGDirectLink.Checked == true)
{
command.Parameters.AddWithValue("@tasktype", "Direct Link");
}
else
{
command.Parameters.AddWithValue("@tasktype", "Keyword");
}
if (txtDGKeyword.Text == "ROME")
{
command.Parameters.AddWithValue("@keyword", "");
}
else
{
command.Parameters.AddWithValue("@keyword", txtDGKeyword.Text);
}
if (radioDGDirectLink.Checked == true)
{
command.Parameters.AddWithValue("@link", txtDGDirectLink.Text);
}
else
{
command.Parameters.AddWithValue("@link", txtDGHomePage.Text);
}
command.Parameters.AddWithValue("@profile", cboProfiles.Text);
command.Parameters.AddWithValue("@10email", txtDGGoogleEmail.Text);
command.Parameters.AddWithValue("@10pass", txtDGGooglePassword.Text);
command.Parameters.AddWithValue("@ID", txtID.Text);
command.CommandText = query;
command.ExecuteNonQuery();
RefreshDBConnection();
connection.Close();
MessageBox.Show("Task Edited");
this.Close();
}
Here is additional code for opening EditTask form inside my form1:
private void btnEditTask_Click(object sender, EventArgs e)
{
if (dataTasks.SelectedRows.Count < 0)
{
MessageBox.Show("You must select one user!");
return;
}
DataGridViewRow row = dataTasks.SelectedRows[0]; // We will select first selected row. If there are multiple selected rows we will select just first one
int uid = Convert.ToInt32(row.Cells["ID"].Value);
string eplatform = row.Cells["PLATFORM"].Value.ToString();
string etasktype = row.Cells["TASK TYPE"].Value.ToString();
string elink = row.Cells["LINK"].Value.ToString();
string ekeyword = row.Cells["KEYWORD"].Value.ToString();
string eprofile = row.Cells["PROFILE"].Value.ToString();
string e10cemail = row.Cells["10C EMAIL"].Value.ToString();
string e10cpassword = row.Cells["10C PASSWORD"].Value.ToString();
string egoogleemail = row.Cells["GOOGLE EMAIL"].Value.ToString();
string egooglepassword = row.Cells["GOOGLE PASSWORD"].Value.ToString();
string eproxy = row.Cells["PROXY"].Value.ToString();
//I am using `using` since `Form` is disposable class and instead of later doing sf.Dispose() i use `using`. This way we take care of perfomance
using (EditTask f3 = new EditTask(uid, eplatform, etasktype, elink, ekeyword, eprofile, e10cemail, e10cpassword, egoogleemail, egooglepassword, eproxy, this))
{
f3.ShowDialog();
}
}
Please let me know if I can add anything else. Thank you! I'm using C# and Visual Studio btw.
Comments
Post a Comment