일반
프로시저 sql 생성쿼리 테이블에 보여주기 기능
알 수 없는 사용자
2022. 4. 6. 11:46
SMALL
if (tabControl1.SelectedTab == tabPage2)
{
//프로시저 보여주기메소드
showProceaser();
for (int num = 0; num < dataGridView3.Rows.Count; num++)
{
string tbl = dataGridView3.Rows[num].Cells[0].Value.ToString();
if (tbl == null) return;
string queryCreate = "SHOW CREATE PROCEDURE " + tbl;
dgvShowAll(queryCreate, num);
}
}
void dgvShowAll(string queryCreate, int number)
{
try
{
_HostName = textBoxIp1.Text;
_PORT = textBoxPort1.Text;
_DATABASE = textBoxDb1.Text;
_ID = textBoxUn1.Text;
_PWD = textBoxPw1.Text;
_HostName2 = textBoxIp2.Text;
_PORT2 = textBoxPort2.Text;
_DATABASE2 = textBoxDb2.Text;
_ID2 = textBoxUn2.Text;
_PWD2 = textBoxPw2.Text;
StringBuilder _strArg = new StringBuilder("");
StringBuilder _strArg2 = new StringBuilder("");
_strArg.Append("Server = "); // SQL
_strArg.Append(_HostName); // 서버
_strArg.Append(";Port = ");
_strArg.Append(_PORT); // 포트
_strArg.Append(";Database = ");
_strArg.Append(_DATABASE); // 데이터베이스
_strArg.Append(";username = ");
_strArg.Append(_ID); // ID
_strArg.Append(";password = ");
_strArg.Append(_PWD); // PWD
_strArg.Append(";");
_strArg.Append("Charset=utf8;");
_strArg2.Append("Server = "); // SQL
_strArg2.Append(_HostName2); // 서버
_strArg2.Append(";Port = ");
_strArg2.Append(_PORT2); // 포트
_strArg2.Append(";Database = ");
_strArg2.Append(_DATABASE2); // 데이터베이스
_strArg2.Append(";username = ");
_strArg2.Append(_ID2); // ID
_strArg2.Append(";password = ");
_strArg2.Append(_PWD2); // PWD
_strArg2.Append(";");
_strArg2.Append("Charset=utf8;");
MySqlConnection con = new MySqlConnection(_strArg.ToString());
MySqlConnection con2 = new MySqlConnection(_strArg2.ToString());
con.Open();
con2.Open();
MySqlDataReader rdr = DBConnect(con, queryCreate);
MySqlDataReader rdr2 = DBConnect(con2, queryCreate);
List<Columns> listTable1 = new List<Columns>();
List<Columns> listTable2 = new List<Columns>();
List<ColumnsAll> listTableAll = new List<ColumnsAll>();
while (rdr.Read())
{
Columns listInfo = new Columns() { CREATETABLE = rdr["Create Procedure"].ToString() };
listTable1.Add(listInfo);
}
if (rdr2 == null)
{
rdr2 = rdr;
}
while (rdr2.Read())
{
Columns listInfo = new Columns() { CREATETABLE = rdr2["Create Procedure"].ToString() };
listTable2.Add(listInfo);
}
for (int k = 0; k < listTable1.Count; k++)
{
listTableAll.Add(new ColumnsAll()
{
CREATETABLE1 = listTable1[k].CREATETABLE
});
dataGridView3.Rows[number].Cells[4].Value = listTableAll[0].CREATETABLE1;
}
for (int k = 0; k < listTable2.Count; k++)
{
bool found = false;
for (int j = 0; j < listTableAll.Count; j++)
{
if (listTable2[k].CREATETABLE == listTableAll[j].CREATETABLE1)
{
listTableAll[j].CREATETABLE2 = listTable2[k].CREATETABLE;
found = true;
break;
}
}
if (found == false)
{
listTableAll.Add(new ColumnsAll()
{
CREATETABLE2 = listTable2[k].CREATETABLE,
});
}
dataGridView3.Rows[number].Cells[4].Value = listTableAll[0].CREATETABLE1;
dataGridView3.Rows[number].Cells[9].Value = listTableAll[0].CREATETABLE2;
}
string createQuery = listTable1[0].CREATETABLE;
Create(createQuery);
con.Close();
con2.Close();
}
catch (Exception e)
{
LogMgr.ExceptionLog(e);
MessageBox.Show(e.ToString());
}
}
LIST