Click here to Skip to main content
15,888,113 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Data.SqlServerCe;

namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");


mail.From = new MailAddress("ajay.raturi22@gmail.com");
mail.To.Add("vicky16792@gmail.com");
mail.CC.Add(new MailAddress("sunny.raturi7@gmail.com", "Ajay raturi"));
mail.Bcc.Add(new MailAddress("shubham14091991@gmail.com", "Shubham"));
mail.Subject = "Test Mail - 1";
mail.Body = "mail with attachment";

//mail.CC.Add("ajay.raturi22@gmail.com", "Ajay");
//mail.AddCC("Chilkat HR", "vicky16792@gmail.com");
//mail.AddMultipleCC(new MailAddress(""Jack Frost <vicky16792@gmail.com>", "Bob <ajay.raturi22@gmail.com>"));

System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("C://Users/adiuser1/Downloads/Capture.PNG");
mail.Attachments.Add(attachment);

SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("ajay.raturi22@gmail.com", "976079905666");
SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);
MessageBox.Show("mail Send");
}

catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}

private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}


private void button2_Click(object sender, EventArgs e)
{

SqlCeConnection x;
// SqlCeCommand y;
string constr = Properties.Settings.Default.vikasConnectionString;
try
{
x = new SqlCeConnection(constr);
x.Open();
string query="INSERT INTO insert(email,name) values ('" + textBox1.Text + "', '" + textBox2.Text + "')";
SqlCeCommand myCommand = new SqlCeCommand(query, x);
int result=myCommand.ExecuteNonQuery();

MessageBox.Show("hahahaha");
x.Close();
}
catch(Exception ex)
{
throw ex;
}
}


private void Form1_Load(object sender, EventArgs e)
{

}
}}
Posted

Hi,

You are using the query as:
C#
string query="INSERT INTO insert(email,name) values ('" + textBox1.Text + "', '" + textBox2.Text + "')";


Insert is a reserved word. If that is your table name use [Insert]
Like,
C#
string query="INSERT INTO [insert](email,name) values ('" + textBox1.Text + "', '" + textBox2.Text + "')";


If not, then check your table name in the insert query.

Hope this helps !! :) :)

Regards,
Praneet
 
Share this answer
 
Comments
Member 11188441 29-Oct-14 2:04am    
hey i apply the answer but in database the vale is not save in the table.why this happen?
[no name] 29-Oct-14 2:07am    
Apply debugger and see what is query formed. copy this and try running it your DB.
Try and check where the problem is
SQL
string query="INSERT INTO insert(email,name) values ('" + textBox1.Text + "', '" + textBox2.Text + "')";


you have a table called 'insert' ? really ?? that's bad practice - as you can see by the error, the sql statement parser doesn't like it !!!

create a table with a different name eg email_raw and try the SQL again, eg

string query="INSERT INTO email_raw(email,name) values ('" + textBox1.Text + "', '" + textBox2.Text + "')";


btw, putting SQL together like that is also a bad idea, but lets get it going before we cover that
 
Share this answer
 
Comments
Member 11188441 29-Oct-14 2:04am    
hey i apply the answer but in database the vale is not save in the table.why this happen?
[no name] 29-Oct-14 2:06am    
I agree Garth :)
Garth J Lancaster 29-Oct-14 2:18am    
heh - nice work mate - you and I have answered 2 questions now, and you're seconds ahead of me - btw, your answer on the float problem was better than mine, at least you allowed for a double if the float value passed in was too large
[no name] 29-Oct-14 2:19am    
hehe Thanks buddy :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900