如何解决使用 Npgsql
studid lastname firstname
2019-5011 Samplelastname1 Samplefirstname1
2002-3111 Samplelastname2 Samplefirstname2
对于StudentController,这是我目前的代码
string query = "";
public string Getstudid(string studid)
{
dbconn db = new dbconn();
NpgsqlConnection con = new NpgsqlConnection(db.con_str);
con.open();
NpgsqlCommand cmd = con.CreateCommand();
NpgsqlTransaction trans;
trans = con.BeginTransaction();
cmd.Connection = con;
cmd.Transaction = trans;
cmd.CommandText = "select studid,lastname,firstname from public.student_dummy where studid = '" + studid + "'";
cmd.ExecuteNonQuery();
trans.Commit();
con.dispose();
return query;
}
这是我的观点 @model App.Models.Student
<form asp-controller="" asp-action="GetStudid" method="get">
<p>
ID #: <input type="text" name="studid" />
<input type="submit" value="Search" />
</p>
</form>
<table>
<tr>
<th>Personal information</th>
</tr>
<tr>
<td>Lastname:</td>
<td>@Html.displayFor(model => model.studlastname)</td>
</tr>
<tr>
<td>Firstname:</td>
<td>@Html.displayFor(model => model.studfirstname)</td>
</tr>
</table>
url 中也没有错误,它说 https://localhost:44306/?studid=2019-5011 并且它不会像这样返回
个人信息
姓氏:示例姓氏1
名字:示例名字1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。