使用 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 (将#修改为@)