Jump to content

Зареждане на DataGridView


Препоръчан пост

Здравейте! Искам да свържа SQLite база данни с C# приложение, но имам проблеми.Опитах с този код, но datagridview-a не се зарежда. Помощ!

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.Data.SQLite;
namespace PasswordManager
{
    public partial class Form1 : Form
    {
	 
		    private DataTable dt;
		    public Form1()
		    {
				    InitializeComponent();
				    this.dt = new DataTable();
			 
			 
														   
		    }
	 
		    private SQLiteConnection SQLiteConnection;
		    private void DataClass()
		    {
				    SQLiteConnection = new SQLiteConnection("Data Source=PasswordManager.s3db;Version=3;");
		    }
	 
		    private void GetData()
		    {
					  SQLiteDataAdapter DataAdapter;
					  try
					  {
								    SQLiteCommand cmd;
								    SQLiteConnection.Open();  //Initiate connection to the db
								    cmd = SQLiteConnection.CreateCommand();
								    cmd.CommandText = "select*from PasswordManager;";  //set the passed query
								    DataAdapter = new SQLiteDataAdapter(cmd);
								    DataAdapter.Fill(dt); //fill the datasource
								    dataGridView1.DataSource = dt;
					  }
					  catch(SQLiteException ex)
					  {
								    //Add your exception code here.
					  }
					  SQLiteConnection.Close();
				   
		    }

Link to comment
Сподели другаде

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Гост
Отговори на тази тема

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   Не можете да качите директно снимка. Качете или добавете изображението от линк (URL)

Loading...
×
×
  • Създай ново...