C# winforms, how to show records in datagridview if there is more than one record from...

  • Thread starter Thread starter Kevin Rea
  • Start date Start date
K

Kevin Rea

Guest
Hi guys,

I am new to C#. I am experienced with VBA, though that really does not have that much to do with this..

I have a datagridview on my winform, that I want to only show with data if there is more than one record existing with the CallSign that
is currently on the form itself.

This is the code I have for the datagridview
***************************
OleDbCommand command = new OleDbCommand();
connection2.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\HamLogBookV10\hamlogbook.accdb;
Persist Security Info=False;";
command.Connection = connection2;

string query2 = "select CallSign, CallDate, FullName, [Band], Freq, Mode, City, State, Country From Main WHERE (CallSign = "+txtCallSign.Text+")";

command.CommandText = query2;
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataTable dz = new DataTable();
da.Fill(dz);
mainDataGridView1.DataSource = dz;
****************************
so, what I want to happen is, on the form above this datagridview, are all the text fields.
the one field that I am interested in is txtCallSign, so if it already has 1 or more existing records in the database file
with the same callsign, then I want to populate the datagridview with those records, otherwise, the datagridview does
not need to be populated.

thanks very much,
Kevin Rea
Lancaster, Calif.

Continue reading...
 
Back
Top