I am very new programming and very very inexperienced.
I started to program a desktop application in WPF with C # and as a database I use SQLite since the data I use is very simple and I do not require a more powerful database manager.
Within my solution I decide to include a class to manipulate the database which is the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SQLite;
using System.Data;
namespace DashEnt
{
class DbMani
{
private String cadena = "data source=DbDash.db";
public SQLiteConnection cn;
private SQLiteCommandBuilder cmb;
public DataSet ds = new DataSet();
public SQLiteDataAdapter da;
public SQLiteCommand comando;
private void conectar()
{
cn = new SQLiteConnection(cadena);
}
public DbMani()
{
conectar();
}
//Metodo para Consultas
public void consultar(string sql, string tabla)
{
ds.Tables.Clear();
da = new SQLiteDataAdapter(sql, cn);
cmb = new SQLiteCommandBuilder(da);
da.Fill(ds, tabla);
}
//Metodo para Eliminar
public bool eliminar(string tabla, string condicion)
{
cn.Open();
string sql = "delete from " + tabla + " where " + condicion;
comando = new SQLiteCommand(sql, cn);
int i = comando.ExecuteNonQuery();
cn.Close();
if (i > 0)
{
return true;
}
else
{
return false;
}
}
//Metodo para Actualizar
public bool actualizar(string tabla, string campos, string condicion)
{
cn.Open();
string sql = "update " + tabla + " set " + campos + " where " + condicion;
comando = new SQLiteCommand(sql, cn);
int i = comando.ExecuteNonQuery();
cn.Close();
if (i > 0)
{
return true;
}
else
{
return false;
}
}
//Metodo consultas para combos
public DataTable consucom(string tabla)
{
string sql = "select * from " + tabla;
da = new SQLiteDataAdapter(sql, cn);
DataSet dts = new DataSet();
da.Fill(dts, tabla);
DataTable dt = new DataTable();
dt = dts.Tables[tabla];
return dt;
}
//Metodo para insertar datos
public bool insertar(string sql)
{
cn.Open();
comando = new SQLiteCommand(sql, cn);
int i = comando.ExecuteNonQuery();
cn.Close();
if (i > 0)
{
return true;
}
else
{
return false;
}
}
}
}
So far everything seems normal, in the main form I have a datagrid, I urge the class mentioned above as follows:
DbMani obDatos = new DbMani();
When loading the form I want the datagrid to be filled in, for this I do the following:
private void MainWindow_Load(object sender, RoutedEventArgs e)
{
obDatos.consultar("select * from TabBitacora", "TabBitacora");
this.dataApp.ItemsSource = obDatos.ds.Tables["TabBitacora"];
}
and here is the error that tells me:
Sorry for the bad catch, basically what the error tells me is:
(Field) System.Data.DataSet.DbMani.ds Unable to convert implicitly type System.Data.DataTable in System.Collections. | Enumerable. There is already an explicit conversion (check if you are missing some conversion)
I'm probably making a fool of myself, could someone tell me which?
Thank you very much.
Greetings.