Answer the question
In order to leave comments, you need to log in
Mapping a table from a sqlite database in C#?
I connected the database using the example, when you click on the menu item, the form opens but the table from the database is not displayed, which code is wrong? seems to be correct and without error
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SQLite;
using System.Data.SQLite.EF6;
using System.Data.SQLite.Linq;
using System.IO;
namespace UchetPeremesheniaMaterialov
{
public partial class planSchetov : Form
{
private SQLiteConnection sql_con;
private SQLiteCommand sql_cmd;
private DataSet DS = new DataSet();
private DataTable DT = new DataTable();
private string sPath = Path.Combine(Application.StartupPath, @"C:\Users\EvgenieL\Documents\Visual Studio 2013\Projects\UchetPeremesheniaMaterialov\UchetPeremesheniaMaterialov\mybd.db");
public planSchetov()
{
InitializeComponent();
}
private void planSchetov_Load(object sender, EventArgs e)
{
string ConnectionString = @"Data Source=" + sPath + ";New=False;Version=3";
String selectCommand = "Select * from planSchetov";
}
public void selectTable(string ConnectionString, String selectCommand)
{
SQLiteConnection connect = new
SQLiteConnection(ConnectionString);
connect.Open();
SQLiteDataAdapter dataAdapter = new
SQLiteDataAdapter(selectCommand, connect);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
dataGridView1.DataSource = ds;
dataGridView1.DataMember = ds.Tables[0].ToString();
connect.Close();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
}
}
Answer the question
In order to leave comments, you need to log in
SQLiteConnection con;
SQLiteCommand cmd;
DataTable dt;
con = new SQLiteConnection();
con.ConnectionString = @"Data Source=" + sPath + ";New=False;Version=3";
cmd = new SQLiteCommand();
cmd.Connection = con;
dt = new DataTable();
dataGridView1.DataSource = dt; // связываешь DataTable и таблицу на форме (просто dt)
con.Open(); // открываешь соединение с БД
cmd.CommandText = "Select * from planSchetov";
dt.Clear();
dt.Load(cmd.ExecuteReader()); // выполняешь SQL-запрос
con.Close(); // закрываешь соединение с БД
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question