sql query from combobox's and textbox , help please

Eng Michael Hanna 1 Reputation point
2022-09-09T13:20:59.477+00:00

239526-1.jpg

my fist question here , am 1 year experience in c# sql >> the point is i have table named : Pa_Info

when i select data from combo box's i need it to display to DataGrid view , if i didn't type in text box , bring the rest needed data

help please , thanks in advance

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,828 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,700 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,237 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,036 Reputation points
    2022-09-09T14:21:45.937+00:00

    Best recommendation is to use the builder pattern as done with the NuGet package SqlKata with documentation here.

    Simple select code sample getting data from two ComboBox controls SELECT * FROM [Contacts] WHERE [FirstName] = @p0 AND [LastName] = @p1

    using var cn = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=NorthWind2020;Integrated Security=True");  
    SqlServerCompiler compiler = new ();  
      
    var db = new QueryFactory(cn, compiler);  
      
    var query = db.Query("Contacts");  
      
    // add first condition  
    query = query.Where("FirstName", ContactFirstNameComboBox.Text);  
      
    // add another condition  
    query = query.Where("LastName", ContactLastNameComboBox.Text);  
    SqlResult result = compiler.Compile(query);  
      
    // this is the SQL statement parameterized  
    string sql = result.Sql;