CorNokZ
Currently a stay at home dad
- Joined
- Jan 24, 2004
- Messages
- 19,779
Hey guys. I'm doing this project where I need to store data and search for it again. I can easily store all the data in my Access Database, and I can make it pump out all of the information again, but I can't search for a specific piece of data.
 
The assignment is to make a program for a garage so the can easily put cars into the system and find them again. I know that I somehow have to filter my search, but I really have no idea how to do it. I want to be able to search for the license plate number and pull out the infos on that car. I am thinking of doing so, "simply" by having a textbox, a search button and a textblock
 
Any help is very much appreciated
 
edit. It is the second button that is causing me trouble
 
	
	
	
		
			
			The assignment is to make a program for a garage so the can easily put cars into the system and find them again. I know that I somehow have to filter my search, but I really have no idea how to do it. I want to be able to search for the license plate number and pull out the infos on that car. I am thinking of doing so, "simply" by having a textbox, a search button and a textblock
Any help is very much appreciated
edit. It is the second button that is causing me trouble
		Code:
	
	using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.OleDb;
 
namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
 
            OleDbConnection cn = new OleDbConnection();
            cn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\Anders\Documents\Databaser\biler.mdb;User Id=;Password=;";
            cn.Open();
            Application.Current.Properties["DBConnection"] = cn;
        }
 
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            OleDbConnection conn = (OleDbConnection)Application.Current.Properties["DBConnection"];
 
            string bil = textBox1.Text;
            string regnr = textBox3.Text;
            string reps = textBox4.Text;
            string model = textBox2.Text;
 
 
            string StrSQL = "INSERT INTO Biler (mærke, model, registreringsnummer, reparationer) VALUES ('" + bil + "', '" + model + "', '" + regnr + "', '" + reps + "')";
            OleDbCommand InsertCommand = new OleDbCommand(StrSQL, conn);
            InsertCommand.ExecuteNonQuery();
            MessageBox.Show("Data stored successfully");
 
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
        }
 
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            textBlock1.Text = "";
            OleDbConnection conn = (OleDbConnection)Application.Current.Properties["DBConnection"];
 
            string StrSQL = "SELECT * FROM Biler WHERE Registreringsnummer";
            OleDbCommand SelectCommand = new OleDbCommand(StrSQL, conn);
 
            // Opret et DataReader objekt
            using (OleDbDataReader minDataReader = SelectCommand.ExecuteReader())
            {
                // Gennemløb resultaterne
                while (minDataReader.Read())
                {
                    textBlock1.Text +=
                    "Registreringsnummer: " + minDataReader["Registreringsnummer"].ToString() + "\n" +
                    "Bil: " + minDataReader["Mærke"].ToString() + "\n" +
                    "Model: " + minDataReader["Model"].ToString() + "\n" +
                    "Reparationer: " + minDataReader["Reparationer"].ToString() + "\n";
 
                }
            }
        }
    }
} 
					
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		