I am trying to display the data in the datagridview
in windows form.
I have following code to fetch data from the database.
public DataSet GetUser(string custName)
{
string connString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\Amrit\\Desktop\\Database.accdb ;Persist Security Info=False;";
DataSet dataSet = new DataSet();
OleDbConnection oleConn = new OleDbConnection(connString);
try
{
oleConn.Open();
string sql = "SELECT * FROM [Customer] WHERE [Customer's Ebayname]=" + custName;
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(sql, oleConn);
dataAdapter.Fill(dataSet, "Customer");
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
oleConn.Close();
}
if (dataSet.Tables.Count <= 0)
return null;
else
return dataSet;
}
Above I am passing the value of custName
from the textBox
in the windows form. This will display all the rows containing that name.
Here, how I am trying to display the data.
private void button1_Click(object sender, EventArgs e)
{
DataSet ds = GetUser(textBox1.Text);
dataGridView1.DataSource = ds;
}
Can somebody point out where I am wrong?