}
}
m_Sdr.Close();
m_Scon.Close();
}
catch
{
if(m_Scon.State.ToString().ToUpper()=="OPEN")
{
m_Scon.Close();
}
}
}
#endregion
#region Show Columns in a table DropDownList1_SelectedIndexChanged
/// <summary>
/// 显示表的所有列
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
try
{
if(this.DropDownList1.SelectedIndex!=-1)
{
m_Scon.ConnectionString = "user id=" this.txtUserName.Text
";password=" this.txtPassword.Text
";initial catalog=" this.DropDownList3.SelectedItem.Text
";data source=" this.txtServerName.Text;
SqlCommand m_Scmd = new SqlCommand("sp_columns",m_Scon);
m_Scmd.CommandType = CommandType.StoredProcedure;
SqlParameter myParm = m_Scmd.Parameters.Add("@table_name",SqlDbType.VarChar,100);
myParm.Value = this.DropDownList1.SelectedItem.Value;
m_Scon.Open();
SqlDataReader m_Sdr = m_Scmd.ExecuteReader();
this.DropDownList2.Items.Clear();
while(m_Sdr.Read())
{
ListItem m_LI = new ListItem();
m_LI.Text = m_Sdr["COLUMN_NAME"].ToString();
m_LI.Value = m_Sdr["COLUMN_NAME"].ToString();
this.DropDownList2.Items.Add(m_LI);
}
m_Sdr.Close();
m_Scon.Close();
}
}
catch
{
if(m_Scon.State.ToString().ToUpper()=="OPEN")
{
m_Scon.Close();
}
}
}
#endregion
#region Show All DataBase Button2_Click
/// <summary>
/// 显示所有数据库
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button2_Click(object sender, System.EventArgs e)
{
try
{
m_Scon.ConnectionString = "user id=" this.txtUserName.Text
";password=" this.txtPassword.Text
";data source=" this.txtServerName.Text;
SqlCommand m_Scmd = new SqlCommand("sp_databases",m_Scon);
m_Scmd.CommandType = CommandType.StoredProcedure;
m_Scon.Open();
SqlDataReader m_Sdr = m_Scmd.ExecuteReader();
this.DropDownList1.Items.Clear();
while(m_Sdr.Read())
{
ListItem m_LI = new ListItem();
m_LI.Text = m_Sdr["DATABASE_NAME"].ToString();
m_LI.Value = m_Sdr["DATABASE_NAME"].ToString();
this.DropDownList3.Items.Add(m_LI);
}
m_Sdr.Close();
m_Scon.Close();
}
catch
{
if(m_Scon.State.ToString().ToUpper()=="OPEN")
{
m_Scon.Close();
}
}
}
#endregion
#region Make Form
/// <summary>
/// 生成表单项
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button3_Click(object sender, System.EventArgs e)
{
if(this.DropDownList1.SelectedIndex!=-1)
{
m_Scon.ConnectionString = "user id=" this.txtUserName.Text
";password=" this.txtPassword.Text
";initial catalog=" this.DropDownList3.SelectedItem.Text
";data source=" this.txtServerName.Text;
SqlCommand m_Scmd = new SqlCommand("sp_columns",m_Scon);
m_Scmd.CommandType = CommandType.StoredProcedure;
SqlParameter myParm = m_Scmd.Parameters.Add("@table_name",SqlDbType.VarChar,100);
myParm.Value = this.DropDownList1.SelectedItem.Value;
m_Scon.Open();
SqlDataReader m_Sdr = m_Scmd.ExecuteReader();
string ColName = "";
string ColType = "";
while(m_Sdr.Read())
文章整理:西部数码--专业提供域名注册、虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!



