Exemplo n.º 1
0
        public List <Ventor> GetAllVentors()
        {
            List <Ventor> ventorDetails = new List <Ventor>();

            using (SqlConnection conn = new SqlConnection(connStr))
            {
                string     query = "SELECT * FROM Ventor";
                SqlCommand cmd   = new SqlCommand(query, conn);
                conn.Open();
                using (SqlDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read() == true)
                    {
                        Ventor vd = new Ventor
                        {
                            ventorNumber = ((int)reader["VentorNumber"]).ToString(),
                            Name         = reader["Name"].ToString().Trim(),
                            City         = reader["City"].ToString().Trim(),
                            Street       = reader["Street"].ToString().Trim(),
                            ZipCode      = reader["ZipCode"].ToString().Trim(),
                            PhoneNumber  = reader["PhoneNumber"].ToString().Trim(),
                        };
                        ventorDetails.Add(vd);
                    }
                }
            }
            return(ventorDetails);
        }
Exemplo n.º 2
0
        private void Add_Click1(object sender, EventArgs e)
        {
            //string Message;
            Ventor v = new Ventor();

            {
                v.ventorNumber = textBoxVentorNumber.Text;
                v.Name         = textBoxName.Text;
                v.City         = textBoxCity.Text;
                v.Street       = textBoxStreet.Text;
                v.ZipCode      = textBoxZipCode.Text;
                v.PhoneNumber  = textBoxPhoneNumber.Text;
            };
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("INSERT INTO Ventor(VentorNumber, Name, City, Street, ZipCode, PhoneNumber) values(@VentorNumber, @Name, @City, @Street, @ZipCode, @PhoneNumber)");
                string query = sb.ToString();
                conn.Open();
                SqlCommand cmd = new SqlCommand(query, conn);
                cmd.Parameters.AddWithValue("@VentorNumber", v.ventorNumber);
                cmd.Parameters.AddWithValue("@Name", v.Name);
                cmd.Parameters.AddWithValue("@City", v.City);
                cmd.Parameters.AddWithValue("@Street", v.Street);
                cmd.Parameters.AddWithValue("@ZipCode", v.ZipCode);
                cmd.Parameters.AddWithValue("@PhoneNumber", v.PhoneNumber);
                cmd.ExecuteNonQuery();
                dataGridView1.Rows.Clear();
                ConstructDataGridView1();
            }
        }