0

我从列表框中插入了数据。我想在 gridview 中检索特定技能集的数据。例如,如果我在下拉列表中选择 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);

} 
4

2 回答 2

1

在配置期间,无论您拥有 SkillsetID 还是其他任何东西,都已配置好您的 gridview 数据源,为此,请使用“WHERE”子句,该子句表示 SkillSetID 绑定到 ID 为 lstBasePackageAsset 且带有“选定值”或只是“选定”的“控件” " 即 gridview1.skillsetID = lstBasePackageAsset.selectedvalue ;

你会完成的。

请下次,甚至现在,让人们知道它是 VisualStudio 查询还是任何其他开发源查询。在 VS 中更容易,但在命令行中需要更多的编程代码(如果你这样做的话)

string query="select * from  Employees where skill= '" +yourvalue+ "'";
于 2013-02-01T05:26:30.987 回答
1

是的,您可以使用这样的where子句来执行此操作

string query="select * from  Employees where skill= '" +yourvalue+ "'";
于 2013-02-01T05:41:49.677 回答