public List <Accountbo> ViewAccount() { SqlConnection con = new SqlConnection("server= intvmsql01; user id =PJ09TMS101_1718; database=DB09TMS101_1718;password= tcstvm"); con.Open(); SqlCommand cmd = new SqlCommand("sp_viewaccount", con); cmd.CommandType = CommandType.StoredProcedure; SqlDataReader reader = cmd.ExecuteReader(); List <Accountbo> listacc = new List <Accountbo>(); while (reader.Read()) { Accountbo A1 = new Accountbo(); A1.Accountid = Convert.ToInt32(reader["accid"]); A1.Amount = Convert.ToInt32(reader["amount"]); A1.Acctype = reader["acctype"].ToString(); A1.Cid = Convert.ToInt32(reader["cusid"]); listacc.Add(A1); } return(listacc); }
public int AddAccount(Accountbo A) { try { SqlConnection con = new SqlConnection("server= intvmsql01; user id =PJ09TMS101_1718; database=DB09TMS101_1718;password= tcstvm"); con.Open(); SqlCommand cmd = new SqlCommand("sp_addaccount_5", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@customerid", A.Cid); cmd.Parameters.AddWithValue("@amount", A.Amount); cmd.Parameters.AddWithValue("@acctype", A.Acctype); cmd.Parameters.AddWithValue("@accid", 0); cmd.Parameters["@accid"].Direction = ParameterDirection.Output; int ra = cmd.ExecuteNonQuery(); if (ra > 0) { int ai = Convert.ToInt32(cmd.Parameters["@accid"].Value); return(ai); } else { return(0); } } catch (Exception E) { throw E; } }
protected void Button1_Click(object sender, EventArgs e) { int cusid = Convert.ToInt32(TextBox1.Text); int amount = Convert.ToInt32(TextBox2.Text); string atype = DropDownList1.SelectedItem.Value; DateTime dt = DateTime.Now; asd.Text = "" + dt; Accountbo A = new Accountbo(amount, atype, cusid); CustomerMethods CM = new CustomerMethods(); try { int aid = CM.AddAccount(A); aid1.Text = "" + aid; } catch (Exception Ex) { //if (Ex.Message.Contains("ForeignKeyException")) //{ Response.Write("<script>alert('The Customer Id doesn't Exists')</script>"); //} } astatus.Text = "Active"; }