C# Masters

madbuddy

Active member
  • Feb 6, 2010
    712
    169
    43
    muthu ate....
    private TextBox SetText(ComboBox _combo)
    {
    TextBox _tmpBox = new TextBox();

    switch (_combo.Text)
    {
    case "Large":
    _tmpBox.Text = "LRG" + (GetMaxID() + 1).ToString();
    break;

    //add other two also

    default:
    break;
    }
    return _tmpBox;
    }

    private int GetMaxID()
    {
    //Quary to take the max id from table column and return
    //return (int)//SELECT MAX(ItemID) FROM dbo.TableName
    }

    //In Combo box itemChange event
    private void ComboBoxItemchangeEvent(object sender, EventArgs e)
    {
    textbox= SetText(sender as ComboBox);
    }
     
    • Like
    Reactions: GRO_MAX

    GRO_MAX

    Well-known member
  • Aug 2, 2009
    4,299
    137
    63
    private TextBox SetText(ComboBox _combo)
    {
    TextBox _tmpBox = new TextBox();

    switch (_combo.Text)
    {
    case "Large":
    _tmpBox.Text = "LRG" + (GetMaxID() + 1).ToString();
    break;

    //add other two also

    default:
    break;
    }
    return _tmpBox;
    }

    private int GetMaxID()
    {
    //Quary to take the max id from table column and return
    //return (int)//SELECT MAX(ItemID) FROM dbo.TableName
    }

    //In Combo box itemChange event
    private void ComboBoxItemchangeEvent(object sender, EventArgs e)
    {
    textbox= SetText(sender as ComboBox);
    }

    Thank you machan switch statement ekak danna puluwan kiyala hithuneth oyage code eka dakkata passe machan, thanks a lot, ubata hariyanawa machan anith minissunta udaw karana nisama. rep+
     
    Jul 5, 2009
    817
    249
    0
    At home
    1. Uba connection ekak hadaganin Database ekata.... Then eke ItemID Field eka ganin


    private void cmbx_SelectedIndexChanged(object sender, EventArgs e)
    {
    SqlConnection myConnection = ???? // Ube Connection eka
    SqlCommand myCommand = new SqlCommand("select ItemID from Table where category="'+cmbx.SelectedValue+'"ORDER BY ItemID DESC", myConnection); // Ube Table names n field names ekka meka edit karaganin ( waradda ganna epa )
    SqlDataReader myReader = myCommand.ExecuteReader();

    String S = myReader["Item ID"].ToString(); // While ekak danna epa because Last record eka ganna one nisa


    2. Then Substring karapan ena value eka and convert to Integer


    string substrng = S.Substring(3, 6); // Database eken gaththu record eka kadagannawa
    int convertedstrng = int.Parse(substrng) // Convert karanawa integer walata mokada DB eken retrieve wenne text ekak nisa

    3. Finally Append karapan

    if (cmbx.SelectedValue == "Large")
    Textbox1.text = "LGR"+"convertedstrng";
    else if (cmbx.SelectedValue == "Small")
    Textbox1.text = "SML"+"convertedstrng";
    else if (cmbx.SelectedValue == "Extra Large")
    Textbox1.text = "EXL"+"convertedstrng";

    }

    Hope this will do
     
    Jul 5, 2009
    817
    249
    0
    At home
    private TextBox SetText(ComboBox _combo)
    {
    TextBox _tmpBox = new TextBox();

    switch (_combo.Text)
    {
    case "Large":
    _tmpBox.Text = "LRG" + (GetMaxID() + 1).ToString();
    break;

    //add other two also

    default:
    break;
    }
    return _tmpBox;
    }

    private int GetMaxID()
    {
    //Quary to take the max id from table column and return
    //return (int)//SELECT MAX(ItemID) FROM dbo.TableName
    }

    //In Combo box itemChange event
    private void ComboBoxItemchangeEvent(object sender, EventArgs e)
    {
    textbox= SetText(sender as ComboBox);
    }

    But machan i have a question...... Database eke ItemID field eka thiyenne numeric nemei ne ..... So max item ekak ganna puluwanda....Anika DB eken retrieve wenne text ekakne machan

    As an example:
    Db eke last record eka widiyata aththe LRG0002 kiyamu.... So TEXT ne... ?? ithin max puluwanda??

    Also eka integer walata convert karanne nathuwa apita +1 kiyanna ba machan...... so eka convert karanna one......

    Mama harida danne na.... Pahadili karanu mana.... :):):)
     

    madbuddy

    Active member
  • Feb 6, 2010
    712
    169
    43
    muthu ate....
    But machan i have a question...... Database eke ItemID field eka thiyenne numeric nemei ne ..... So max item ekak ganna puluwanda....Anika DB eken retrieve wenne text ekakne machan

    As an example:
    Db eke last record eka widiyata aththe LRG0002 kiyamu.... So TEXT ne... ?? ithin max puluwanda??

    Also eka integer walata convert karanne nathuwa apita +1 kiyanna ba machan...... so eka convert karanna one......

    Mama harida danne na.... Pahadili karanu mana.... :):):)


    Uba kiyana eka eththa machan.muu ID kiyala auto increment field ekak daagaththanam hari.
     

    ♥-Aurora-♥

    Well-known member
  • Jun 5, 2010
    4,309
    942
    113
    තාමත් වැඩේ හරි ගියෙ නැත්තම් මේ ටික කියන්න:
    - ඩේටබේස් එකේ තියෙන columns
    - IDs හැදෙන්නෙ LGR0001 , SML0002, EXL0003, LGR0004 , SML0005, EXL0006 වගේද
    නැත්නම් LGR0001 , SML0001, EXL0001, LGR0002 , SML0002, EXL0002 වගේද? :)
     
    Last edited:
    Jul 5, 2009
    817
    249
    0
    At home
    ♥-Aurora-♥;13814456 said:
    තාමත් වැඩේ හරි ගියෙ නැත්තම් මේ ටික කියන්න:
    - ඩේටබේස් එකේ තියෙන columns
    - IDs හැදෙන්නෙ LGR0001 , SML0002, EXL0003, LGR0004 , SML0005, EXL0006 වගේද
    නැත්නම් LGR0001 , SML0001, EXL0001, LGR0002 , SML0002, EXL0002 වගේද? :)

    Table 3k dagaththanan thama godak honda....ehemath naththan eka Field ekaka LGR , SML , EXL and thawa field ekaka number eka.... then Display karanakota Field deka combine karala pennanna :):):)
     
    • Like
    Reactions: GRO_MAX

    ♥-Aurora-♥

    Well-known member
  • Jun 5, 2010
    4,309
    942
    113
    Table 3k dagaththanan thama godak honda....ehemath naththan eka Field ekaka LGR , SML , EXL and thawa field ekaka number eka.... then Display karanakota Field deka combine karala pennanna :):):)

    tables 3ක් නම් කරදරයි. එකෙන් ගොඩ යන්න පුලුවන්. මෙයා කෝමද කරලා තියෙන්නෙ දන්නෙ නෑ :oo:
     

    GRO_MAX

    Well-known member
  • Aug 2, 2009
    4,299
    137
    63
    ♥-Aurora-♥;13814456 said:
    තාමත් වැඩේ හරි ගියෙ නැත්තම් මේ ටික කියන්න:
    - ඩේටබේස් එකේ තියෙන columns
    - IDs හැදෙන්නෙ LGR0001 , SML0002, EXL0003, LGR0004 , SML0005, EXL0006 වගේද
    නැත්නම් LGR0001 , SML0001, EXL0001, LGR0002 , SML0002, EXL0002 වගේද? :)
    machan oya colors walin dala thiyana widiyata ganna puluwan nam godak hodai, but machan mata eka karaganna amaru nisa thamai machan mama ara widiyata damme machan
     

    GRO_MAX

    Well-known member
  • Aug 2, 2009
    4,299
    137
    63
    ♥-Aurora-♥;13814669 said:
    tables 3ක් නම් කරදරයි. එකෙන් ගොඩ යන්න පුලුවන්. මෙයා කෝමද කරලා තියෙන්නෙ දන්නෙ නෑ :oo:
    ow machan table combine karanna mata idea ekakuth naha machan ape claz eke hodiya witharak kiyala dila anith ewa apita thaniyama igena ganna kiyala loku project ekak dunna ekai machan me danna ayagen ahagena goda yanna try ekak denna hadanne :(
     

    GRO_MAX

    Well-known member
  • Aug 2, 2009
    4,299
    137
    63
    machan dinith oya niyametama describe karala dala thiyanawa thak you machan rep dennam machan dan nam naha, e nathath ubalata hariyanawa machan.
     

    GRO_MAX

    Well-known member
  • Aug 2, 2009
    4,299
    137
    63
    ela ela :):):) Gud Luck with ur project machann
    SqlCommand myCommand = new SqlCommand("select ItemID from Table where category="'+cmbx.SelectedValue+'"ORDER BY ItemID DESC", myConnection)

    machan methane poddak therenne naha machan oya category kiyala dala thiyenne mokakda?
     
    Jul 5, 2009
    817
    249
    0
    At home
    SqlCommand myCommand = new SqlCommand("select ItemID from Table where category="'+cmbx.SelectedValue+'"ORDER BY ItemID DESC", myConnection)

    machan methane poddak therenne naha machan oya category kiyala dala thiyenne mokakda?

    e machan ube table eken category kiyala field ekak thiyenawa kiyala hithala kiuwe.... ehema ekak naththan where condition eka nathuwa dapan.....
     

    GRO_MAX

    Well-known member
  • Aug 2, 2009
    4,299
    137
    63
    e machan ube table eken category kiyala field ekak thiyenawa kiyala hithala kiuwe.... ehema ekak naththan where condition eka nathuwa dapan.....

    mama machan database ekata category kiyala ekak add kara machan, dan machan errors naha bt run wenakota

    String S = myReader["itemId"].ToString();

    methanadi kiyanawa Invalid attempt to read when no data is present. ekata hethuwa mokakda machan koheda mata waradune ?
     
    Jul 5, 2009
    817
    249
    0
    At home
    mama machan database ekata category kiyala ekak add kara machan, dan machan errors naha bt run wenakota

    String S = myReader["itemId"].ToString();

    methanadi kiyanawa Invalid attempt to read when no data is present. ekata hethuwa mokakda machan koheda mata waradune ?

    Ehema error ekak enawa kiyanne machan database eken mukuth read wela na kiyana ekai...... Ube category field eke thiyena spellings ube program eke widiyatama thiyenna one... e kiuwe....

    Table eke thiyenne LARGE kiyalanam program eketh checkbox eke danna one LARGE kiyalamai..........podi hari spelling mistakes thiyanna epa...... Capital simple ewath ain karala eka format ekakata ganin
     

    GRO_MAX

    Well-known member
  • Aug 2, 2009
    4,299
    137
    63
    machan mata oyage me programme ekata match wena widiyata database eka create karaganna widiya kiyanawada?

    mage batabase eke addItems kiyala Table ekak thiyanawa eke itemId int kiyala column ekakui category varchar(50) kiyalacolumn ekakui thiynawa eka waradiye neda?
     
    Last edited:

    GRO_MAX

    Well-known member
  • Aug 2, 2009
    4,299
    137
    63
    machan checkbox ekakin meweine compbobox ekakin neda api category eka select karanne?
     
    Last edited:
    Jul 5, 2009
    817
    249
    0
    At home
    machan mata oyage me programme ekata match wena widiyata database eka create karaganna widiya kiyanawada?

    mage batabase eke addItems kiyala Table ekak thiyanawa eke itemId kiyala column ekakui category kiyalacolumn ekakui thiynawa eka waradiye neda?

    Na machan eka hari....... hari uba danata arake where condition eke eka ain karala try ekak deela balapanko

    e kiuwe

    select ItemID from Table ORDER BY ItemID DESC

    meken data ekak hari enawanan oka weda karai..... meka hariyagaththata passe eelaga step eka karapan
     
    Jul 5, 2009
    817
    249
    0
    At home
    machan mata oyage me programme ekata match wena widiyata database eka create karaganna widiya kiyanawada?

    mage batabase eke addItems kiyala Table ekak thiyanawa eke itemId int kiyala column ekakui category varchar(50) kiyalacolumn ekakui thiynawa eka waradiye neda?

    Ahhhhh mata kiyapan ube table eke thaama eka data ekakwath nadda :baffled::baffled::baffled::baffled::baffled::baffled: