protected void Submit_Click(object sender, EventArgs e)
{
// create a new SqlConnection object with the appropriate connection string
SqlConnection sqlConn = new SqlConnection();
sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;
SqlConnection updatesql = new SqlConnection();
updatesql.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;
SqlConnection selectsql = new SqlConnection();
selectsql.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;
SqlConnection insertsql = new SqlConnection();
insertsql.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;
SqlConnection connection = new SqlConnection();
connection.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ConnectionString;
SqlCommand MyCommand;
SqlCommand insertCommand;
SqlCommand updateCommand;
selectsql.Open();
// do some operations ...
string cmdStr = "SELECT * FROM BusinessName WHERE MerchantEmail='" + MerchantEmailTextBox.Text + "'";
SqlDataAdapter dataAdapter = new SqlDataAdapter(cmdStr, selectsql);
DataSet ds = new DataSet();
dataAdapter.Fill(ds, "MyDataSet");
selectsql.Close();
// just count the no of rows
int RowCount = ds.Tables[0].Rows.Count;
Label2.Text = "" + RowCount;
// if zero rows returned than no such user exists
if (RowCount == 0)
{
//nothing match in our business database
Label1.Text = "Nothing Match ";
insertsql.Open();
//we need to insert this new merchant and send email to it.
string cmd1 = "INSERT INTO BusinessName(MerchantEmail, EmailSent, Unsubscribe, EmailRequest) VALUES('" + MerchantEmailTextBox.Text + "','1','1','1')";
insertCommand = new SqlCommand(cmd1, insertsql);
insertCommand.ExecuteNonQuery();
insertsql.Close();
sendEmail();
//End of inserting and email sending
}
else if (RowCount == 1)
{
// also save other information if required
int emailsent = (int)(ds.Tables[0].Rows[0][1]);
int emailrequest = (int)(ds.Tables[0].Rows[0][3]);
//matched something in the business database
Label1.Text = "Something matched " + emailsent + " " + emailrequest;
if (emailsent == 0)//we can send email to merchant
{
//send email
sendEmail();
emailsent = 1;
string cmd3 = "UPDATE BusinessName SET EmailSent = '" + emailsent + "' WHERE MerchantEmail='" + MerchantEmailTextBox.Text + "'";
connection.Open();
SqlCommand updateconncommand = new SqlCommand(cmd3, connection);
updateconncommand.ExecuteNonQuery();
connection.Close();
}
else//emailsent is 1, we can not send email
{
//Start of updating
//email-request's value need to be increased at here
emailrequest++;
// Label1.Text = "Email Sent: "+emailsent +" and Email Request: "+emailrequest;
string cmd2 = "UPDATE BusinessName SET EmailRequest = '" + emailrequest + "' WHERE MerchantEmail='" + MerchantEmailTextBox.Text + "'";
updatesql.Open();
updateCommand = new SqlCommand(cmd2, updatesql);
updateCommand.ExecuteNonQuery();
updatesql.Close();
//end of updating
}
}
DateTime date = DateTime.Now;
sqlConn.Open();
string cmd = "INSERT INTO Nomination (NominationDate, CoName, CoPhone, CoEmail, CoContact, CoProvince, CoCountry, MFirstName, MLastName, MEmail, MDistIDNum, MDomain) VALUES ('" + date + "','" + MerchantTextBox.Text + "','" + MerchantPhoneTextBox.Text + "','" + MerchantEmailTextBox.Text + "','" + MerchantContactNameTextBox.Text + "','" + MerchantProvinceTextBox.Text + "','" + MerchantCountryTextBox.Text + "','" + MemFirstNameTextBox.Text + "','" + MemLastNameTextBox.Text + "','" + MemEmailTextBox.Text + "','" + RepNumTextBox.Text + "','" + RepWebTextBox.Text + "')";
MyCommand = new SqlCommand(cmd, sqlConn);
MyCommand.ExecuteNonQuery();
Label3.Text = "Inserting..........";
sqlConn.Close();
}
Here is my code. I don't know where are wrong. Thanks to give some suggestion.