I have looked at many videos and answers, on the web I now have a working example.
I wish to drag and drop files onto a panel and have the name I provide plus a path to the file recorded into the database. Some examples show three lines for the SQL part I have one.
SqlCeCommand cmd = new SqlCeCommand("INSERT INTO NStacks(NStacksName, NStacksItem)VALUES((textBox1.Text) + (File))", con);
Others have different lines.
When the program is executed normally without the SQL query then the line
MessageBox.Show("Attempted write DB " + textBox1.Text +" "+ File);
will display the given information that should be entered into the Database.
I am now faced with database error messages which I don’t know what exactly is wrong.
“There was an error parsing the query. [Token line number =1,Token line offset =72,Token in error = File]".
My Code is outlined below.
namespace NStacks1
{
public partial class Form1 : Form
{
SqlCeConnection con = new SqlCeConnection("Data Source=C:\\Users\\userename\\Documents\\Visual Studio 2010\\Projects\\NStacks1\\NStacks1\\NStacks.sdf");
SqlCeCommand cmd;
public Form1()
{
InitializeComponent();
}
private void panel1_DragDrop(object sender, DragEventArgs e)
{
if (textBox1.Text.Equals(""))
{
MessageBox.Show("Blank name please enter a name and try again.");
}
else
{
string[] Files = (string[])e.Data.GetData(DataFormats.FileDrop, false);
foreach (string File in Files)
{
try
{
con.Open();
SqlCeCommand cmd = new SqlCeCommand("INSERT INTO NStacks(NStacksName, NStacksItem)VALUES((textBox1.Text) + (File))", con);
cmd.ExecuteNonQuery();
MessageBox.Show("Attempted write DB " + textBox1.Text +" "+ File);
con.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
con.Close();
}
}
}
}
private void panel1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.All;
}
}
}