我正在尝试在今年夏天在学校创建一个进程调度程序,这对于使用VB来说还是一个新手。目前,我有一个绑定到“EmployeeBindingSource”的组合框,它为公司中的每个员工保存信息。为每个员工分配建筑物中每个工作站的技能等级。我想要做的是,如果一名员工被列为具有“0”技能,那么装配站在选择分配给装配站的员工时,该特定员工将不会出现在组合框中。
通过做一些研究,我相信不是将组合框绑定到设计器中的数据源,而是必须在表单加载的代码中为每个组合框分配值。
This is the access table that holds all the employee information
在表格中我们可以看到Steve在AS_Level类别(程序集)中的技能等级为“0”。
目前,所有数据绑定都在设计器中针对每个组合框进行,因此没有为数据绑定编写代码。目前,每个组合框都绑定到访问表中的“Full_Name”列。
同样,我对VB很陌生,所以如果这太模糊,我会道歉。如果我能提供更多有用的信息,请告诉我。谢谢大家。
添加此处建议的代码后,我有
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
datafile = "C:\Users\Jacob\Desktop\Halton\HaltonProject.accdb"
connString = provider & datafile
myConnection.ConnectionString = connString
myConnection.Open()
Dim str As String
str = "SELECT * FROM [Employee] WHERE (SP_Level <> '" & 0 & "')"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
Dim dr As OleDbDataReader = cmd.ExecuteReader
Dim userfound As Boolean = False
Dim Full_Name As String
While dr.Read
userfound = True
Full_Name = dr("Full_Name").ToString
SP_Emp1.Items.Add(Full_Name)
SP_Emp2.Items.Add(Full_Name)
SP_Emp3.Items.Add(Full_Name)
SP_Emp4.Items.Add(Full_Name)
End While
myConnection.Close()
现在完全运作!
答案 0 :(得分:1)
根据您的评论和帖子,我假设,左侧的复选框启用/禁用该行上的组合框,并且如果您更改查询,则单独绑定它们,使其如下所示:
protected void Export2Excel(object sender, EventArgs e)
{
gridViewRow.Cells[11].Visible = true;
gridViewRow.Cells[11].Style["display"] = "inline";
Response.ClearContent();
Response.AppendHeader("content-disposition", "attachment; filename=Mobile.xls");
Response.ContentType = "application/excel";
StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);
GridView currentGridView = new GridView();
switch (DeviceType())
{
case "cell":
currentGridView = gvCellResults;
break;
case "loaner":
currentGridView = gvCellResults;
break;
case "wireless":
currentGridView = gvCellResults;
break;
case "smartphone":
currentGridView = gvSmartPhoneResults;
break;
}
foreach (GridViewRow gridViewRow in currentGridView.Rows)
{
gridViewRow.ForeColor = Color.Black;
HyperLink phonenumber = new HyperLink();
HyperLink imei = new HyperLink();
HyperLink employee = new HyperLink();
foreach (TableCell gridViewRowTableCell in gridViewRow.Cells)
{
phonenumber = (HyperLink)gridViewRowTableCell.FindControl("hrefPhoneNumber");
imei = (HyperLink)gridViewRow.Cells[1].FindControl("hrefIMEI");
employee = (HyperLink)gridViewRow.Cells[6].FindControl("hrefEmpName");
gridViewRowTableCell.Style["forecolor"] = "#000000";
}
if (gridViewRow.RowType == DataControlRowType.DataRow)
{
for (int columnIndex = 0; columnIndex < gridViewRow.Cells.Count; columnIndex++)
{
gridViewRow.Cells[columnIndex].Attributes.Add("class", "text");
gridViewRow.Cells[columnIndex].Text = gridViewRow.Cells[columnIndex].Text.StripTags();
}
if (phonenumber != null)
gridViewRow.Cells[0].Text = phonenumber.Text;
if (imei != null)
gridViewRow.Cells[1].Text = imei.Text;
if (employee != null)
gridViewRow.Cells[6].Text = employee.Text;
}
}
currentGridView.RenderControl(htmlTextWriter);
string style = @"<style> .text { mso-number-format:\@; } </style> ";
Response.Write(style);
Response.Write(stringWriter.ToString());
Response.End();
}
请注意,where子句会根据您的需要而有所不同,因此可以是Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [Employee] WHERE AS_Level <> 0 , myConnection) Dim dr As OleDbDataReader = cmd.ExecuteReader
或WHERE AS_Level <> 0
,依此类推。
我从未使用Ole数据库,因此我对语法不太确定,希望这会有所帮助。