Kevin Rea
asked on
C# winforms, how to show records in datagridview if there is more than one record from matching text field
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.ConnectionStri ng = @"Provider=Microsoft.ACE.O LEDB.12.0; Data Source=C:\HamLogBookV10\ha mlogbook.a ccdb;
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.DataSour ce = 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.
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.ConnectionStri
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.DataSour
**************************
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This way you are populating grid only if there is data returned from database.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I think the points should all be given to srikanthreddyn143. That poster was first to answer the actual question. I only added some management to the code the OP posted.