Here is the model class for my database
x
public class Person
{
public int id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string PhoneNumber { get; set; }
public string Fullinfo
{
get
{
return FirstName + " " + LastName + " " + Email;
}
}
}
And here is the main class
public partial class DashBoard : Form
{
List<Person> persons =new List<Person>();
public DashBoard()
{
InitializeComponent();
Updated();
}
public void Updated()
{
PeopleFoundListbox.DataSource = persons;
PeopleFoundListbox.DisplayMember = "Fullinfo";
}
public void Searchpeoplebutton_Click(object sender, EventArgs e)
{
persons = Getpeople(Lastnametextbox.Text);
Updated();
}
public List<Person> Getpeople(string searchname)
{
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(Helper.Cnn("peopleDb")))
{
var output = connection.Query<Person>("select * from People where Lastname= " + searchname).ToList();
return output;
}
}
}
I want to select records based on last name I have a row having david as last name but when ever I type david in textbox and search I get this error
Invalid column name david
Advertisement
Answer
deleted the answer since it creates a risk of sql injection ; see the other answer instead.