public ActionResult manip(bankapp c, string op) { SqlConnection con = new SqlConnection("user id=sa;password=123;data source=Muktar;database=REMOTE"); SqlCommand cmd = new SqlCommand(); cmd.Connection = con; switch (op) { case "search": cmd.CommandText = "select * from bankapp where accno=@accno"; cmd.Parameters.AddWithValue("@accno", c.accno); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { ViewBag.accno = dr["accno"]; ViewBag.accname = dr["accname"]; ViewBag.balance = dr["balance"]; } dr.Close(); con.Close(); break; case "delete": cmd.CommandText = "delete from bankapp where accno = @accno"; cmd.Parameters.AddWithValue("@accno", c.accno); con.Open(); cmd.ExecuteNonQuery(); con.Close(); break; case "update": cmd.CommandText = "update bankapp set accno=@accno , accname=@accname, balance=@balance where accno = @accno"; cmd.Parameters.AddWithValue("@accno", c.accno); cmd.Parameters.AddWithValue("@newaccno", c.accno); cmd.Parameters.AddWithValue("@accname", c.accname); cmd.Parameters.AddWithValue("@balance", c.balance); con.Open(); cmd.ExecuteNonQuery(); con.Close(); break; } return(View("Index")); }
public ActionResult store(bankapp c) { if (ModelState.IsValid) { SqlConnection con = new SqlConnection("user id=sa;password=123;database=REMOTE;data source=MUKTAR"); SqlCommand cmd = new SqlCommand("insert into bankapp values(@accno , @accname,@balance)", con); cmd.Parameters.AddWithValue("@accno", c.accno); cmd.Parameters.AddWithValue("@accname", c.accname); cmd.Parameters.AddWithValue("@balance", c.balance); con.Open(); cmd.ExecuteNonQuery(); con.Close(); return(View("Index")); } return(View("Index")); }