Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Visual Studio, Creating a search button

Status
Not open for further replies.

AliRazoR

Advanced Member level 4
Joined
Oct 26, 2010
Messages
115
Helped
4
Reputation
8
Reaction score
4
Trophy points
1,298
Activity points
2,001
Hi

i want to create a simple search button in visual studio but it gives error, here is the code:



Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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 searchbutton
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void btn_search_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\searchbutton.mdf;Integrated Security=True;User Instance=True");
            DataTable dt = new DataTable();
            SqlDataAdapter SDA = new SqlDataAdapter("SELECT * FROM searchbutton.mdf where id like" + txt_id.Text, conn);
            SDA.Fill(dt);
            dataGridView1.DataSource = dt;
 
 
 
 
        }
    }
}



thanks in advance
 

Attachments

  • Untitled.jpg
    Untitled.jpg
    199.2 KB · Views: 132
Last edited by a moderator:

What is this SQL statement "SELECT * FROM searchbutton.mdf where id like"

It should be table name instead of "searchbutton.mdf"

EX: if you want to search Employee data then table name should be employee so SQL statement as

"SELECT * FROM employee where id like"
 
thanks for reply but it gives error again,

 

I guess that you missed the single quote (') check this

("SELECT * FROM dbo.contact where id like '" + txt_id.Text + "'" , conn);
 
thank you so much, it is working now :))
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top