Click here to Skip to main content
15,910,981 members
Home / Discussions / WPF
   

WPF

 
Question[WPF] Datagrid With Dynamic column Pin
mjaniaut4-Feb-20 19:57
mjaniaut4-Feb-20 19:57 
AnswerRe: [WPF] Datagrid With Dynamic column Pin
Gerry Schmitz4-Feb-20 21:21
mveGerry Schmitz4-Feb-20 21:21 
AnswerRe: [WPF] Datagrid With Dynamic column Pin
Richard Deeming5-Feb-20 0:48
mveRichard Deeming5-Feb-20 0:48 
QuestionIm new bie help me fix 1 erorr on wpf, i cant do it? Pin
Member 1468037212-Jan-20 16:07
Member 1468037212-Jan-20 16:07 
GeneralRe: Im new bie help me fix 1 erorr on wpf, i cant do it? Pin
Richard MacCutchan12-Jan-20 22:12
mveRichard MacCutchan12-Jan-20 22:12 
AnswerRe: Im new bie help me fix 1 erorr on wpf, i cant do it? Pin
ZurdoDev13-Jan-20 1:07
professionalZurdoDev13-Jan-20 1:07 
QuestionRoutedEvent Pass EventArg Pin
Kevin Marois11-Jan-20 16:42
professionalKevin Marois11-Jan-20 16:42 
AnswerRe: RoutedEvent Pass EventArg Pin
Gerry Schmitz11-Jan-20 20:24
mveGerry Schmitz11-Jan-20 20:24 
GeneralRe: RoutedEvent Pass EventArg Pin
Kevin Marois12-Jan-20 10:05
professionalKevin Marois12-Jan-20 10:05 
GeneralRe: RoutedEvent Pass EventArg Pin
Gerry Schmitz13-Jan-20 13:23
mveGerry Schmitz13-Jan-20 13:23 
GeneralRe: RoutedEvent Pass EventArg Pin
Kevin Marois14-Jan-20 5:18
professionalKevin Marois14-Jan-20 5:18 
GeneralRe: RoutedEvent Pass EventArg Pin
Kevin Marois14-Jan-20 5:43
professionalKevin Marois14-Jan-20 5:43 
AnswerRe: RoutedEvent Pass EventArg Pin
Richard Deeming13-Jan-20 8:00
mveRichard Deeming13-Jan-20 8:00 
GeneralRe: RoutedEvent Pass EventArg Pin
Kevin Marois14-Jan-20 9:02
professionalKevin Marois14-Jan-20 9:02 
QuestionCalculate the textbox value based on the value of combobox ? ( wpf ) Pin
Member 146803727-Jan-20 19:44
Member 146803727-Jan-20 19:44 
QuestionRe: Calculate the textbox value based on the value of combobox ? ( wpf ) Pin
Richard MacCutchan7-Jan-20 21:17
mveRichard MacCutchan7-Jan-20 21:17 
AnswerRe: Calculate the textbox value based on the value of combobox ? ( wpf ) Pin
Member 146803727-Jan-20 21:49
Member 146803727-Jan-20 21:49 
SuggestionRe: Calculate the textbox value based on the value of combobox ? ( wpf ) Pin
Richard Deeming8-Jan-20 0:46
mveRichard Deeming8-Jan-20 0:46 
Member 14680372 wrote:
string sql = " select * from comboboxnew where code = '" + comboBox1.SelectedItem + "';";
Don't do it like that!

Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.

Everything you wanted to know about SQL injection (but were afraid to ask) | Troy Hunt[^]
How can I explain SQL injection without technical jargon? | Information Security Stack Exchange[^]
Query Parameterization Cheat Sheet | OWASP[^]

C#
private void ComboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    using (SqlConnection con = new SqlConnection("Data Source=LEAN-22\\SQLEXPRESS;Initial Catalog=LUAT;Integrated Security=True"))
    using (SqlCommand cmd = new SqlCommand("SELECT TOP 1 * FROM comboboxnew WHERE code = @code;"))
    {
        cmd.Parameters.AddWithValue("@code", Convert.ToString(comboBox1.SelectedItem));
        
        con.Open();
        
        using (SqlDataReader myreader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
        {
            if (myreader.Read())
            {
                string code = myreader.GetInt32(0).ToString();
                string pieces = myreader.GetInt32(1).ToString();
                string layers = myreader.GetInt32(2).ToString();
                string productionpieces = myreader.GetInt32(3).ToString();
                string seccond = myreader.GetInt32(4).ToString();
                
                txtcode.Text = code;
                txtpieces.Text = pieces;
                txtlayers.Text = layers;
                txtproductionpieces.Text = productionpieces;
                txtseccond.Text = seccond;
            }
        }
    }
}
NB: You should avoid using SELECT * FROM ...; instead, specify the exact list of fields you want to load.

You'll need to check that Convert.ToString(comboBox1.SelectedItem) returns the value you're expecting. If it's a data-bound list, it might return something like "System.Data.DataRowView" instead, in which case you'll need to do some more work to get the real value.

And you should avoid hard-coding your connection strings. Store them in a configuration file instead. For example:
How to: Read Connection Strings from the Web.config File | Microsoft Docs[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

QuestionRefresh Attached Property? Pin
Kevin Marois7-Jan-20 10:17
professionalKevin Marois7-Jan-20 10:17 
AnswerRe: Refresh Attached Property? Pin
Richard Deeming8-Jan-20 1:18
mveRichard Deeming8-Jan-20 1:18 
QuestionWPF Exception - Send Error Report Pin
Kevin Marois30-Dec-19 7:41
professionalKevin Marois30-Dec-19 7:41 
AnswerRe: WPF Exception - Send Error Report Pin
Richard MacCutchan30-Dec-19 10:13
mveRichard MacCutchan30-Dec-19 10:13 
AnswerRe: WPF Exception - Send Error Report Pin
jimmson2-Jan-20 3:15
jimmson2-Jan-20 3:15 
AnswerRe: WPF Exception - Send Error Report Pin
Gerry Schmitz2-Jan-20 20:09
mveGerry Schmitz2-Jan-20 20:09 
AnswerRe: WPF Exception - Send Error Report Pin
Mycroft Holmes3-Jan-20 10:49
professionalMycroft Holmes3-Jan-20 10:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.