0% found this document useful (0 votes)
2 views

excodc#2

The document is a C# Windows Forms application code that defines a form for querying a database of employees. It includes a button to consult the database based on the name entered in a text box and displays the results in a grid. Additionally, there is a button to exit the form, and error handling is implemented for database operations.

Uploaded by

Victor Afonso
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

excodc#2

The document is a C# Windows Forms application code that defines a form for querying a database of employees. It includes a button to consult the database based on the name entered in a text box and displays the results in a grid. Additionally, there is a button to exit the form, and error handling is implemented for database operations.

Uploaded by

Victor Afonso
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace bacnodados
{
public partial class frmListaFunc : Form
{
public frmListaFunc()
{
InitializeComponent();
}

private void btnConsultar_Click(object sender, EventArgs e)


{

try
{

String sql = "Select * from func Where Nome like'" + txtNome.Text


+ "%'";
string stringConexao = "Data Source=VAIO\\SQLEXPRESS;Initial
Catalog=bd;Integrated Security=True";
SqlConnection con = new SqlConnection();
con.ConnectionString = stringConexao;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = sql;
cmd.Connection = con;
con.Open();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataTable dt = new DataTable();
da.Fill(dt);
grid.DataSource = dt;
}
catch (Exception x)
{
MessageBox.Show(x.Message, "Erro");
}

private void btnSair_Click(object sender, EventArgs e)


{
this.Close();
}
}
}

You might also like