Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

C# Não estou conseguindo conectar ao Banco de Dado SqLite no Visual Studio 2022

Jaenis Alencar

New Coder
Boa noite!!!

Pessoal, eu sou iniciante nesse mundo do programa e o problema pelo qual não estou entendendo é que minhas linhas de códigos que me fazem conectar o meu projeto ao banco de LqLite estão corretas omo mostro a seguir:

Crie uma Classe para fazer a conexao com meu banco de dados

C#:
usando o sistema;
usando System.Collections.Generic;
usando System.Data.SQLite;
usando System.Linq;
usando System.Text;
usando System.Threading.Tasks;
usando System.Windows.Forms;
usando System.Xml.XPath;


namespace SysCadV01
{
    classe interna Bd_Conexao
    {
        public SQLiteConnection Bd_Connect = novo SQLiteConnection ("Fonte de dados =C:\\SysCad_V1\\SysCadV01\\Bd\\Bd_SysCadV1.db");

   
         
        //Abre a conexão com banco de dados
        public void AbrirConexão()
        {
            tentar
            {
                novo SQLiteConnection(Bd_Connect);
                Bd_Connect.Open();  
            }
            //Extorna erro
            pegar (exceção ex)
            {
                MessageBox.Show("Erro ao conectar ao Servidor Sql: " + ex.Message);
            }
         
        }
            //Fecha a conexão com o banco de dados
        public void FecharConexao()
        {
            tentar
            {
                novo SQLiteConnection(Bd_Connect);
                Bd_Connect.Close();
            }
            //Extorna erro
            pegar (exceção ex)
            {
                MessageBox.Show("Erro ao sair do Servidor Sql: " + ex.Message);
            }
        }
                 
    }

}

Dentro do Frm_CadSocios.cs e no botão SALVAR fIz o seguinte:
C#:
usando o sistema;
usando System.Collections.Generic;
usando System.ComponentModel;
usando System.Data;
usando System.Drawing;
usando System.Linq;
usando System.Text;
usando System.Threading.Tasks;
usando System.Windows.Forms;

namespace SysCadV01
{
    classe parcial pública Frm_CadSocios: Formulário
    {
        Bd_Conexao conectarDB=new Bd_Conexao();
        public Frm_CadSocios()
        {
            InitializeComponent();
        }

        private void Btn_Salvar_Click(objeto remetente, EventArgs e)
        {
            DesabilitarCampos();
            LimpaCampo();
            Desabilitar Botões();
            Btn_Novo.Enabled = verdadeiro;
            Btn_Sair.Enabled = verdadeiro;
            conectarDB.AbrirConexao();
           
        }

Então meus amigos vocês podem me ajudar a achar esse erro ficando muito agradecido.
No Aguardo!!
 
Last edited by a moderator:
Could you speak in English and translate some with that code? It would help us help you. If you need it you could try translate.google.com. Sorry if I am not helping, I do not know that language. X E.
 
I can't connect to SqLite Database in Visual Studio 2021
Goodnight!!!

Guys, I'm a beginner in this world of programming and the problem I'm not understanding is that my line of code that connects my project to the LqLite database is correct, as I show below:

I created a class to connect to my database
C#:
usando o sistema;
usando System.Collections.Generic;
usando System.Data.SQLite;
usando System.Linq;
usando System.Text;
usando System.Threading.Tasks;
usando System.Windows.Forms;
usando System.Xml.XPath;


namespace SysCadV01
{
classe interna Bd_Conexao
{
public SQLiteConnection Bd_Connect = novo SQLiteConnection ("Fonte de dados =C:\\SysCad_V1\\SysCadV01\\Bd\\Bd_SysCadV1.db");



//Abre a conexão com banco de dados
public void AbrirConexão()
{
tentar
{
novo SQLiteConnection(Bd_Connect);
Bd_Connect.Open();
}
//Extorna erro
pegar (exceção ex)
{
MessageBox.Show("Erro ao conectar ao Servidor Sql: " + ex.Message);
}

}
//Fecha a conexão com o banco de dados
public void FecharConexao()
{
tentar
{
novo SQLiteConnection(Bd_Connect);
Bd_Connect.Close();
}
//Extorna erro
pegar (exceção ex)
{
MessageBox.Show("Erro ao sair do Servidor Sql: " + ex.Message);
}

and in the Frm _CadSociaextanticiei and called this class on the save button both to connect to the database and also to call the insert into expression

C#:
usando o sistema;
usando System.Collections.Generic;
usando System.ComponentModel;
usando System.Data;
usando System.Drawing;
usando System.Linq;
usando System.Text;
usando System.Threading.Tasks;
usando System.Windows.Forms;

namespace SysCadV01
{
classe parcial pública Frm_CadSocios: Formulário
{
Bd_Conexao conectarDB=new Bd_Conexao();
public Frm_CadSocios()
{
InitializeComponent();
}

private void Btn_Salvar_Click(objeto remetente, EventArgs e)
{
DesabilitarCampos();
LimpaCampo();
Desabilitar Botões();
Btn_Novo.Enabled = verdadeiro;
Btn_Sair.Enabled = verdadeiro;
conectarDB.AbrirConexao();

}
 
Last edited by a moderator:
I don't know anything about C#, but just looking at the indentation of the 2nd file, I can already tell that there are some unclosed curly brackets.
 
Back
Top Bottom