public bool fillcombo1() { bool issucess = false; connclass c = new connclass(); SqlConnection conn = new SqlConnection(c.connection); try { string query = "select* from tbl_catagories"; SqlCommand cmd = new SqlCommand(query, conn); SqlDataReader myreader; conn.Open(); myreader = cmd.ExecuteReader(); while (myreader.Read()) { string sname = myreader.GetString(1); txtcatagory.Items.Add(sname); } } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { conn.Close(); } return(issucess); }
public bool ToGetInvoiceID() { //Create a boolean variable and set its value to false and return it bool issucess = false; int a; //MEthod to connect Database connclass c = new connclass(); SqlConnection conn = new SqlConnection(c.connection); try { //SQL Query to insert Data in DAtabase string query = "Select Max (inv_no) From tbl_invoice"; //For Executing Command SqlCommand cmd = new SqlCommand(query, conn); //Database Connection Open conn.Open(); //To execute reader SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { string val = dr[0].ToString(); if (val == "") { lblinvoiceno.Text = "1"; } else { a = Convert.ToInt32(dr[0].ToString()); a = a + 1; lblinvoiceno.Text = a.ToString(); } } } catch (Exception ex) { //Throw Message if any error occurs MessageBox.Show(ex.Message); } finally { //Closing Connection conn.Close(); } return(issucess); }