none
How to get a auto custom id in textbox and save in database RRS feed

  • Question

  • hi there, i have 4 projects in my solution. 1st is "UI", 2nd is "BAL", 3rd is "DLL" and 4th is "Library". i write a code for custom id and my code working perfectly, only if the code written in only "UI" project form. But i don't want to write all code on UI form. so i write the code on DAL Class, and trying to access using BAL Class, But i the custom id didn't show in textbox.

    Please help me.. here is my code

    Library Project, Class Name: CustomIDEntity

    public string CustomID { get; set; }


    DLL Project, Class Name: CustomIDDLL

    public static string customid(CustomIDEntity cide)
            {
                using (SQLiteConnection conn = new SQLiteConnection("Data Source=customid2.db;Version=3;"))
                {
                    string CommandText = "SELECT * FROM cusid2 order by Id";
                    using (SQLiteCommand cmd = new SQLiteCommand(CommandText, conn))
                    {
                        conn.Open();
                        DataTable dt = new DataTable();
                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(cmd);
                        adapter.Fill(dt);
    
                        if (dt.Rows.Count < 1)
                        {
                            return cide.CustomID = "ABC-1000";
                        }
                        else
                        {
                            int count = dt.Rows.Count;
                            string oldId = dt.Rows[count - 1]["Id"].ToString();
                            string[] array = oldId.Split('-');
                            Int32 value = Convert.ToInt32(array[1]) + 1;
                            return cide.CustomID = "ABC" + "-" + value.ToString();
                        }
                    }
                }
            }


    DAL Project, Class Name: CustomIDBAL

    public static string cusid(CustomIDEntity cide)
            {
                return CustomIDDLL.customid(cide);
            }

    UI Project, Form Name: MainForm

    private void MainForm_Load(object sender, EventArgs e)
            {
                CustomID();
            }
    
            public string CustomID()
            {
                CustomIDEntity cide = new CustomIDEntity();
                cide.CustomID = cusid.Text;
    
                return CustomIDBAL.cusid(cide);
            }
    Help me where i'm wrong.

    Thursday, January 10, 2019 4:28 PM

Answers

  • Maybe you should write this:

    private void MainForm_Load(object sender, EventArgs e)

    {

       cusid.Text = CustomID();

    }

    • Marked as answer by John6272 Thursday, January 10, 2019 5:26 PM
    Thursday, January 10, 2019 5:16 PM

All replies

  • Help me where i'm wrong.

    Did you use the debugger and track the code line by line to see if it actually works?

    Thursday, January 10, 2019 4:37 PM
  • yes i use there is no error but no value show in textbox
    Thursday, January 10, 2019 4:45 PM
  • Maybe you should write this:

    private void MainForm_Load(object sender, EventArgs e)

    {

       cusid.Text = CustomID();

    }

    • Marked as answer by John6272 Thursday, January 10, 2019 5:26 PM
    Thursday, January 10, 2019 5:16 PM
  • Maybe you should write this:

    private void MainForm_Load(object sender, EventArgs e)

    {

       cusid.Text = CustomID();

    }

    Great! this is working. Thanks.

    Thursday, January 10, 2019 5:26 PM