小编use*_*013的帖子

将数据从Textbox INSERT到Postgres SQL

我只是学习如何连接C#和PostgresSQL.我想将数据从tb1(文本框)和tb2插入数据库.但我不知道如何编码我以前的代码是从数据库中选择SELECT.这是我的代码

private void button1_Click(object sender, EventArgs e)
    {
        bool blnfound = false;
        NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;User Id=postgres;Password=admin123;Database=Login");
        conn.Open();
        NpgsqlCommand cmd = new NpgsqlCommand("SELECT * FROM login WHERE name='" + tb1.Text + "' and password = '" + tb2.Text + "'",conn);
        NpgsqlDataReader dr = cmd.ExecuteReader();

        if (dr.Read())
        {
            blnfound = true;
            Form2 f5 = new Form2();
            f5.Show();
            this.Hide();
        }

        if (blnfound == false)
        {
            MessageBox.Show("Name or password is incorrect", "Message Box", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
            dr.Close();
            conn.Close();
        }
    }
Run Code Online (Sandbox Code Playgroud)

所以请帮我代码.

.net c# postgresql npgsql

5
推荐指数
1
解决办法
2万
查看次数

如何在标题栏中添加图像?

标题栏中的图标太小,所以我想添加Image而不是Icon.

c# wpf

3
推荐指数
1
解决办法
2301
查看次数

如何在富文本框中只允许一行

我正在使用WPF(C#).

我希望用户只能在富文本框中键入一行(不能按回车键).谁能告诉我如何设置这种富文本框属性?

c# wpf

3
推荐指数
1
解决办法
2576
查看次数

将位图转换为字节

我正在使用winform(C#).我有图像作为位图,我想将位图转换为字节插入数据库.那么,请你告诉我怎么做?

c# winforms

0
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×4

wpf ×2

.net ×1

npgsql ×1

postgresql ×1

winforms ×1