这是我的问题: 我想让我的代码简短,我的一个朋友告诉我我可以使用 DAL。但我不知道如何使用 DAL。我也尝试搜索互联网。但它并没有给我一些简单的解决方案。我是使用 DAL 的新手
注意:我知道我的选择命令很短,但可以把它想象成一个广泛的数据。
ASPX 代码
<div>
<div>
<asp:Label ID="lbl1" Text="FirstName" runat="server" />
</div>
<div>
<asp:TextBox ID="txtFName" runat="server" />
</div>
<div>
<div>
<asp:Label ID="lbl2" Text="MiddleName" runat="server" />
</div>
<div>
<asp:TextBox ID="txtMName" runat="server" />
</div>
</div>
<div>
<div>
<asp:Label ID="lbl3" Text="LastName" runat="server" />
</div>
<div>
<asp:TextBox ID="txtLName" runat="server" />
</div>
</div>
<div>
<div>
<asp:Label ID="lbl4" Text="Birthday" runat="server" />
</div>
<div>
<asp:TextBox ID="txtBday" runat="server" />
</div>
</div>
<div>
<div>
<asp:Label ID="lbl5" Text="Address" runat="server" />
</div>
<div>
<asp:TextBox ID="txtAdd" runat="server" />
</div>
</div>
</div>
ASPX.cs 代码
protected void Page_Load(object sender, EventArgs e)
{
SelectCommand();
}
private void SelectCommand()
{
SqlCommand sqlSelect = new SqlCommand();
sqlSelect.Connection = conn;
sqlSelect.CommandText = "select FirstName = @FirstName,MiddleName = @MiddleName,LastName = @LastName,BirthDate = @BirthDate, Address = @Address from User";
sqlSelect.CommandType = CommandType.Text;
sqlSelect.Parameters.AddWithValue("@FirstName", txtFName.Text);
sqlSelect.Parameters.AddWithValue("@MiddleName", txtFName.Text);
sqlSelect.Parameters.AddWithValue("@LastName", txtFName.Text);
sqlSelect.Parameters.AddWithValue("@BirthDate", txtBday.Text);
sqlSelect.Parameters.AddWithValue("@Address", txtAdd.Text);
conn.Open();
sqlSelect.ExecuteNonQuery();
conn.Close();
}