question

EngMichaelHanna-6184 avatar image
0 Votes"
EngMichaelHanna-6184 asked EngMichaelHanna-6184 commented

sql query from combobox's and textbox , help please

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


sql-server-generaldotnet-csharpwindows-forms
1.jpg (25.7 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@EngMichaelHanna-6184, Welcome to Microsoft Q&A, have you considered using EnityFramework to display the data in datagirdview based on the sql query. Please see the Microsoft doc Raw SQL Queriesl.


0 Votes 0 ·

1 Answer

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered EngMichaelHanna-6184 commented

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;



· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

am targeting 4.5 dotnet framework , cant install this nug , i need a solution please :( for 5 combo box's and 3 text boxes

0 Votes 0 ·
karenpayneoregon avatar image karenpayneoregon EngMichaelHanna-6184 ·

I just created a 4.5 windows form project and added the NuGet package SqlKata.2.2.0 without any issues.

0 Votes 0 ·

done fixed it , i need to know how to retrieve all data from SQL even its empty or null please .. thanks so much for your help

0 Votes 0 ·