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.SqlClient;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"Data Source=localhost\\sqlexpress;Initial Catalog=master;Integrated Security=True");
public Form1()
{
InitializeComponent();
}
private void textBox1_KeyUp(object sender, KeyEventArgs e)
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = CommandType.Text; // the bug it's here
cmd.CommandText = "select * from consultoria where produto like ('"+textBox1.Text+"%')";
cmd.ExecuteNonQuery();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
con.Close();
dataGridView1.DataSource = dt;
}
}
}