- ·上一篇文章:利用ASP.NET构建网上考试系统
- ·下一篇文章:用ASP.NET结合XML制作广告管理程序
用ASP.NET写你自己的代码生成器
nString = "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())
{
ColName = m_Sdr["COLUMN_NAME"].ToString();
ColType = m_Sdr["TYPE_NAME"].ToString();
}
m_Sdr.Close();
m_Scon.Close();
}
}
#endregion
#region Make object
/// <summary>
/// 生成实体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button4_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 TableNa
";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())
{
ColName = m_Sdr["COLUMN_NAME"].ToString();
ColType = m_Sdr["TYPE_NAME"].ToString();
}
m_Sdr.Close();
m_Scon.Close();
}
}
#endregion
#region Make object
/// <summary>
/// 生成实体
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Button4_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 TableNa
