示例#1
0
        public string IsHeaderValid()
        {
            string tempString = "";

            string[] headerArray = header.ToStringArray();
            foreach (string s in headerArray)
            {
                if (Regex.IsMatch(s, @"[^a-zA-Z\d_]") == true)
                {
                    tempString += " There is at least one name in header with invalid simbol.";
                    break;
                }
            }
            foreach (string s in headerArray)
            {
                if (String.IsNullOrEmpty(s) == true)
                {
                    tempString += " There is at least one empty name in header.";
                    break;
                }
            }
            for (int i = 0; i < headerArray.Length - 1; i++)
            {
                for (int k = i + 1; k < headerArray.Length; k++)
                {
                    if (headerArray[i] == headerArray[k])
                    {
                        tempString += " There is at least one doubled name in header.";
                        break;
                    }
                }
            }


            return(tempString);
        }
示例#2
0
        private void DataView_Load(object sender, EventArgs e)
        {
            string         connectionString = @"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=" + Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Products.mdf") + ";Integrated Security=True";
            SqlConnection  myConn           = new SqlConnection(connectionString);
            SqlCommand     myCommand        = new SqlCommand("select * from products", myConn);
            SqlDataAdapter myDataAdapter    = new SqlDataAdapter();

            myDataAdapter.SelectCommand = myCommand;
            DataTable myDataTable = new DataTable();

            myDataAdapter.Fill(myDataTable);
            BindingSource myBS = new BindingSource();

            myBS.DataSource          = myDataTable;
            dataGridView1.DataSource = myBS;
            myDataAdapter.Update(myDataTable);
            myConn.Close();

            string[] _header = header.ToStringArray();
            for (int i = 0; i < _header.Length; i++)
            {
                dataGridView1.Columns[i].HeaderText = _header[i];
            }
        }