예제 #1
0
        private string[] GetIDs(DBConnector connector)
        {
            var ids = new string[2];

            var tables = new string[] { "city", "region" };
            var names  = new string[] { "'" + capitalTextBox.Text + "'", "'" + regionTextBox.Text + "'" };

            for (var i = 0; i < 2; i++)
            {
                try
                {
                    var tbName = "dbo." + tables[i];
                    var q      = "SELECT " + tbName + ".id FROM " + tbName +
                                 " WHERE " + tbName + ".name = " + names[i];

                    var ds = connector.GetDataSet(q);

                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        connector.ExecuteQuery("INSERT " + tbName + "(name) VALUES(" + names[i] + ")");
                        ds = connector.GetDataSet(q);
                    }
                    ids[i] = ds.Tables[0].Rows[0].ItemArray[0].ToString();
                }
                catch (SqlException)
                {
                    MessageBox.Show("Some problems with DB");
                    return(null);
                }
            }

            return(ids);
        }
예제 #2
0
파일: MainForm.cs 프로젝트: tihoson/TaskCRM
        private void ShowButtonClick(object sender, EventArgs e)
        {
            string script = File.ReadAllText("../../RequestAll.sql");

            new DataViewForm(DBConnector.GetDataSet(script).Tables[0]).Show(this);
        }