/// <summary>
/// 根据查询字符串返回数据到下拉菜单框
/// </summary>
/// <param name="DropDown_list"></param>
/// <param name="strsql">查询字符串</param>
/// <param name="i">选取其中的字段</param>
/// 创建日期:2008-8-20
/// 创建人:龚德辉
public static void DropDown_List(DropDownList DropDown_list,string strsql,int i)
{
SqlConnection MyConn = new SqlConnection(PublicVar.connectionString);
MyConn.Open();
SqlCommand sc = new SqlCommand(strsql, MyConn);
SqlDataReader sr = sc.ExecuteReader();
int k = 1;
DropDown_list.Items.Insert(0, new ListItem("", "-1"));
while (sr.Read())
{
DropDown_list.Items.Insert(k, new ListItem(sr[i].ToString(), k.ToString()));
k++;
}
sr.Close();
MyConn.Close();
}
/// <summary>
/// 根据查询字符串返回数据到下拉菜单框
/// </summary>
/// <param name="DropDown_list"></param>
/// <param name="strsql">查询字符串</param>
/// <param name="i">选取其中的字段 第一项目为清选择</param>
/// 创建日期:2008-10-20
/// 创建人:龚德辉
public static void DropDown_List_1(DropDownList DropDown_list, string strsql, int i,int j)
{
string connectionString = PublicVar.strCon_SHATDB;
SqlConnection MyConn = new SqlConnection(connectionString);
MyConn.Open();
SqlCommand sc = new SqlCommand(strsql, MyConn);
SqlDataReader sr = sc.ExecuteReader();
int k = 1;
DropDown_list.Items.Insert(0, new ListItem("--请选择--", "-1"));
while (sr.Read())
{
DropDown_list.Items.Insert(k, new ListItem(sr[i].ToString(), sr[j].ToString())); // SQL 列按以0开始
k++;
}
sr.Close();
MyConn.Close();
}
/// <summary>
/// 插入DropDown_list的Item和ID,返回字符串
/// </summary>
/// <param name="DropDown_list"></param>
/// <param name="strsql">查询字符串</param>
/// <param name="str">返回的字符串</param>
/// <param name="i,j,z">选取其中的字段</param>
/// 创建日期:2008-10-15
/// 创建人:龚德辉
public static string DropDownList_String(DropDownList DropDown_list, string strsql,string str, int i, int j,int z)
{
string connectionString = PublicVar.strCon_SHATDB;
SqlConnection MyConn = new SqlConnection(connectionString);
MyConn.Open();
SqlCommand sc = new SqlCommand(strsql, MyConn);
SqlDataReader sr = sc.ExecuteReader();
DropDown_list.Items.Clear();
int k = 0;
while (sr.Read())
{
DropDown_list.Items.Insert(k, new ListItem(sr[i].ToString(), sr[j].ToString()));
k++;
str = sr[z].ToString();
}
sr.Close();
MyConn.Close();
return (str);
}
/// <summary>
/// 文本框接收sql查询的数值
/// </summary>
/// <param name="DropDown_list"></param>
/// <param name="strsql">查询字符串</param>
/// <param name="i">选取其中的字段</param>
/// 创建日期:2008-10-15
/// 创建人:龚德辉
public static void TextBox_GetValue(TextBox Text_Box, string strsql, int i)
{
string connectionString = PublicVar.strCon_SHATDB;
SqlConnection MyConn = new SqlConnection(connectionString);
MyConn.Open();
SqlCommand sc = new SqlCommand(strsql, MyConn);
SqlDataReader sr= sc.ExecuteReader();
if (sr.Read())
{
Text_Box.Text = Text_Box.Text + sr[i].ToString();
}
sr.Close();
MyConn.Close();
}
/// <summary>
/// 返回字符串保存查询的数据
/// </summary>
/// <param name="StringGetValue">函数名</param>
/// <param name="strsql">查询字符串</param>
/// <param name="i">选取其中的字段</param>
/// 创建日期:2008-10-15
/// 创建人:龚德辉
public static string StringGetValue(string str, string strsql, int i)
{
string connectionString = PublicVar.strCon_SHATDB;
SqlConnection MyConn = new SqlConnection(connectionString);
MyConn.Open();
SqlCommand sc = new SqlCommand(strsql, MyConn);
SqlDataReader sr = sc.ExecuteReader();
if (sr.Read())
{
str =sr[i].ToString();
}
sr.Close();
MyConn.Close();
return (str);
}
/// <summary>
/// 返回Int数据
/// </summary>
/// <param name="IntGetValue">函数名</param>
/// <param name="strsql">查询字符串</param>
/// <param name="i">选取其中的字段</param>
/// 创建日期:2008-10-15
/// 创建人:龚德辉
public static int IntGetValue(int Int,string strsql, int i)
{
string ConnectionString = PublicVar.strCon_SHATDB;
SqlConnection MyConn = new SqlConnection(ConnectionString);
MyConn.Open();
SqlCommand Sc = new SqlCommand(strsql, MyConn);
SqlDataReader Sr = Sc.ExecuteReader();
while (Sr.Read())
{
Int = Convert.ToInt32(Sr[i].ToString());
}
Sr.Close();
MyConn.Close();
return (Int);
}
}