I need help i dont know what I am doing wrong because my app runs but dont insert information to database here my code please help me.
/*
* Created by SharpDevelop.
* User: manuel sandoval
* Date: 5/17/2015
* Time: 10:45 AM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using System.Data.SQLite;
namespace MultiControl
{
///<summary>
/// Description of Formdatsprod1.
///</summary>
publicpartialclassFormdatsprod1 : Form
{
publicSQLiteConnectionSqlCON;
publicSQLiteDataAdapter_SqlAd;
publicSQLiteCommandSqlcmd;
publicFormctrlprod_fprods;
publicBooleanlnew = false;
publicDataTable_TProd;
publicFormdatsprod1(Formctrlprod mFProds, SQLiteConnection Sqlcon, SQLiteDataAdapter SqlAd, DataTable TProd )
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
SqlCON = Sqlcon;
_SqlAd = SqlAd;
_TProd = TProd;
_fprods = mFProds;
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
voidFormdatsprod1Load(object sender, EventArgs e)
{
}
voidButton1Click(object sender, EventArgs e)
{
if( lnew == true)
{
// All look well and run but dont update database
DataSet ds = newDataSet();
DataTable dt = newDataTable("productos");
ds.Tables.Add(dt);
SQLiteDataAdapter adaptor = newSQLiteDataAdapter("SELECT * from productos", SqlCON);
SQLiteParameter id_prod = newSQLiteParameter("@id_prod", SqlDbType.VarChar);
SQLiteParameter id_desc = newSQLiteParameter("@id_desc", SqlDbType.Text);
id_prod.Value = textBox1.Text;
id_desc.Value = textBox2.Text;
adaptor.InsertCommand = newSQLiteCommand("INSERT INTO productos(id_producto , descripcion_prod) VALUES(:id_prod, :id_desc)", SqlCON);
adaptor.Fill(ds, "productos");
// if use this code my database is update not the tope code wich i want to use.
// Sqlcmd =SqlCON.CreateCommand();
// Sqlcmd.CommandText = "INSERT INTO productos (id_producto, descripcion_prod) VALUES ('"+textBox1.Text+"', '"+textBox2.Text+"');";
// Sqlcmd.ExecuteNonQuery();
// transaction.Commit();
// }
}
else
{
// This works fine
using (var transaction = SqlCON.BeginTransaction())
{
Sqlcmd =SqlCON.CreateCommand();
Sqlcmd.CommandText = " update productos set descripcion_prod='"+textBox2.Text+"' where id_producto= '"+textBox1.Text+"'";
Sqlcmd.ExecuteNonQuery();
transaction.Commit();
// _fprods.Load();
}
}
lnew=false;
this.Close();
}
}
}