检索列表框的数据
本文关键字:数据 列表 检索 | 更新日期: 2023-09-27 17:56:51
我从列表框中插入了数据。我想在网格视图中检索特定技能集的数据。例如,如果我在下拉列表中选择Android并按下按钮,则必须仅提供具有Android技能的人。有没有人知道如何做到这一点
private string GetConnectionString()
{
//Where DBConnection is the connetion string that was set up in the web config file
return System.Configuration.ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
}
private void InsertRecords(StringCollection sc)
{
SqlConnection conn = new SqlConnection(GetConnectionString());
StringBuilder sb = new StringBuilder(string.Empty);
foreach (string item in sc)
{
const string sqlStatement = "INSERT INTO Table1 (Employees) VALUES";
sb.AppendFormat("{0}('{1}'); ", sqlStatement, item);
}
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Script", "alert('Records Successfuly Saved!');", true);
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
StringCollection sc = new StringCollection();
foreach (ListItem item in ListBox1.Items)
{
if (item.Selected)
{
sc.Add(item.Text);
}
}
InsertRecords(sc);
}
是的,您可以使用这样的where
子句来执行此操作
string query="select * from Employees where skill= '" +yourvalue+ "'";
配置了网格视图数据源,在配置过程中,无论您在哪里拥有SkillsetID或其他任何东西,为此,请使用"WHERE"子句,该子句表示SkillSetID绑定到ID为"控件"的"控件" lstBasePackageAsset 具有"选定值"或只是"选定",即gridview1.skillsetID = lstBasePackageAsset.selectedvalue ;
你会完成的。
请下次,甚至现在,让人们知道它是VisualStudio查询还是任何其他开发源查询。在VS中更容易,但在命令行中需要更多的编程代码(如果你这样做的话)
string query="select * from Employees where skill= '" +yourvalue+ "'";