public void showmenu(display rt) { string insertqry = string.Format("insert into restaurent(name,id,type,location)values('{0}','{1}','{2}','{3}')", rt.Name, rt.Id, rt.Type, rt.Location); using (SqlConnection con = new SqlConnection(constring)) { int i = 0; con.Open(); try { SqlCommand cmd = new SqlCommand(insertqry, con); i = cmd.ExecuteNonQuery(); cmd.Dispose(); } // string querystr = "insert into restaure //string querystr = "select * from product"; catch (Exception ex) { Console.WriteLine(ex.Message); } if (i > 0) { Console.WriteLine("restaurent details entered"); } } }
private static void insertdynamically() { display rt = setdata(); display2 d2 = new display2(); d2.showmenu(rt); display r = new display(); r.showrestaurent(); }
static void Main(string[] args) { display2 d2 = new display2(); display srt = d2.ShowbyId(3); Console.WriteLine("{0}\t{1}\t{2}\t{3}\n", srt.Name, srt.Id, srt.Type, srt.Location); // Console.WriteLine("enter id"); // int Id = Convert.ToInt32(Console.ReadLine()); }
public static display setdata() { Console.WriteLine("enter name"); string name = Console.ReadLine(); Console.WriteLine("enter id"); int id = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("enter type"); string type = Console.ReadLine(); Console.WriteLine("enter location"); string location = Console.ReadLine(); display rts = new display(); rts.Name = name; rts.Id = id; rts.Type = type; rts.Location = location; return rts; }
public display ShowbyId(int id) { string singleqry = "select * from restaurent where Id =" + id; display rtnt = new display(); using (SqlConnection con = new SqlConnection(constring)) { try { con.Open(); SqlCommand cmd = new SqlCommand(singleqry, con); SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { rtnt = new display { Name = dr[0].ToString(), Id = Convert.ToInt32(dr[1]), Type = dr[2].ToString(), Location = dr[3].ToString() }; } } catch (Exception ex) { Console.WriteLine(ex.Message); } return rtnt; } }