【发布时间】:2020-03-26 18:10:25
【问题描述】:
在我的主屏幕上TextBox 和Button。
我需要当用户键入一个数字时,例如:111111,然后按button 这将显示与该数字关联的数据。
需要明确的是,客户必须在TextBox 中输入他们的职务(111111)并按button;按下它应该会显示数据。
这是textbox 和button:
<form id="form">
<div>
@using (Html.BeginForm())
{
<p>
Título: @Html.TextBox("buscar")
<input type="submit" value="Filtrar" /><br />
<input type="button" value="Imprimir" onclick="window.print()" />
</p>
}
</div>
<div>
<table border="1">
@foreach (var item in Model)
{
<tr>
<th scope="row" abbr="Suscriptor">Suscriptor: </th>
<td>
<b>@Html.DisplayFor(modelItem => item.Apellido) @Html.DisplayFor(modelItem => item.Nombre)</b>
</td>
<td>Título: @Html.DisplayFor(modelItem => item.Titulo)</td>
<td>
@Html.ActionLink("Ver detalles en PDF", "PrintPartialViewToPdf", new { id = item.Titulo })
</td>
</tr>
}
</table>
</div>
</form>
这是显示数据的查询代码:CODE UPDATED
public List<Cuotas> cargarDatos(double? tit)
{
List<Cuotas> salida = new List<Cuotas>();
using (SqlConnection conn = new SqlConnection("string"))
{
conn.Open();
SqlCommand comand = new SqlCommand("SELECT titulo, apellido +', '+nombre,cuotas FROM datosSuscripto WHERE titulo = @tit", conn);
var param = comand.Parameters.Add(new SqlParameter("@tit", SqlDbType.Float));
param.Value = tit;
using (SqlDataReader dr = comand.ExecuteReader())
{
while (dr.Read())
{
double titulo = Convert.ToDouble(dr.GetDouble(0));
string nombre = dr.GetString(1);
double cuota = Convert.ToDouble(dr.GetDouble(2));
Cuotas p = new Cuotas(titulo, nombre, cuota);
salida.Add(p);
}
}
conn.Close();
}
return salida;
}
这是控制器代码:
public ActionResult Index(double? consulta)
{
ConexionSQL cn = new ConexionSQL();
return View(cn.cargarDatos(consulta));
}
编译时出现以下错误:
Incorrect syntax near '='//SOLVED
更新新错误:
System.Data.SqlClient.SqlException: 'The parameterized query '(@tit float)SELECT titulo, apellido +', '+nombre,cuotas FROM dat' expects the parameter '@tit', which was not supplied.'
有什么建议吗?有人可以帮帮我吗?
【问题讨论】:
标签: c# sql sql-server model-view-controller