Click here to Skip to main content
16,006,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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.OleDb;

namespace dsc
{
    public partial class user : Form
    {
        static OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\internet\\Documents\\Visual Studio 2008\\Projects\\dsc\\dsc\\dscrec.accdb");

        public user()
        {
            InitializeComponent();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            OleDbCommand cmd = new OleDbCommand("select pin from personal where pin=" + textBox3.Text + "", con);
            con.Open();
            OleDbDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                this.Close();   
            }
            con.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
           
        }

        private void user_Load(object sender, EventArgs e)
        {

        }
    }
}
Posted
Comments
Member 10853826 30-May-14 2:45am    
pls give me a suggestion iam in confussion.when i am debug the error msg occur is
oledb exception is unhandled and below No value given for one or more required parameters.
Prasad Avunoori 30-May-14 2:53am    
At which line you got the error?
Peter Leow 30-May-14 2:54am    
forgot the single quotes:
where pin='" + textBox3.Text + "'"
Actually, you should use parameterized query to prevent sql injection:
http://www.codeproject.com/Articles/604268/Hack-Proof-Your-ASP-NET-Applications-From-SQL-Inje

Inspect the value for the textbox and make sure you have wrapped the text in single quotes.
 
Share this answer
 
forgot the single quotes:
where pin='" + textBox3.Text + "'"

Actually, you should use parameterized query to prevent sql injection:
Hack Proof Your ASP.NET Applications From SQL Injection[^]
 
Share this answer
 
v2
use parameter and set the parameter value
C#
OleDbCommand cmd = new OleDbCommand("select pin from personal where pin=?", con);
cmd.Parameters.AddWithValue("@pin",textBox3.Text);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900