我正在编写一个程序,如果需要将更多数据添加到表单中,该程序将允许用户添加新的空文本字段。我无法理解如何为添加到 GridPane 的每个新字段设置坐标。例如,
btnClick.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent e)
{
TextField text = new TextField();
primaryPane.add(text, 5 , 6);
}});
Run Code Online (Sandbox Code Playgroud)
只会导致在位置 (5,6) 处添加一个新文本字段。如何更改代码以允许用户添加所需数量的字段,并且每个字段都显示在另一个字段之后。我知道我可以对确定数量的新字段使用循环,但是用户应该能够创建任意数量。预先感谢您的任何帮助。
内森
我正在查看参数化查询问题,我找不到使用SqlDataReader参数化查询来填充下拉列表的示例.
现在,我可以在这里使用我的代码填充我的下拉
if (!this.IsPostBack)
{
using (SqlConnection con = new SqlConnection(SQLConnectionString))
{
System.Data.SqlClient.SqlCommand go = new System.Data.SqlClient.SqlCommand();
con.Open();
go.Connection = con;
go.CommandText = "SELECT InsuredID, FirstName, LastName FROM [Lab2].[dbo].[INSURED]";
go.ExecuteNonQuery();
SqlDataReader readIn = go.ExecuteReader();
while (readIn.Read())
{
ddlHomeInsuredID.Items.Add(
new ListItem(readIn["InsuredID"].ToString() + " : " + readIn["FirstName"].ToString()
+ " " + readIn["LastName"].ToString()));
}
con.Close();
ddlHomeInsuredID.Items.Insert(0, new ListItem("--Select InsuredID--", "0"));
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我想让这个select语句参数化.我怎样才能做到这一点?我很乐意编写参数化的插入语句,如下所示:
using (SqlConnection connection = new SqlConnection(SQLConnectionString))
{
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandType = …Run Code Online (Sandbox Code Playgroud)