小编Ash*_*ada的帖子

使用Npgsql for Postgresql的C#查询显示重复的结果和丢失的表数据

我正在检查PostgreSQL是否可以替代SQLServer,我在PostgreSQL公共模式下的测试数据库中创建了一个测试表,并向测试表中添加了两行数据。

现在的问题是,当使用NpgSQL.dll从C#.net运行简单查询时,我得到重复的结果,但并没有显示所有表数据。

这是我使用的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Npgsql;


namespace PlayingWithPostgres
{
    class Program
    {
        static void Main(string[] args)
        {
            // creating the connection string (Server, Port, User id, password, database)
            string conStr = "Server=127.0.0.1; Port=5432; User Id=postgres; Password=Sada1973; Database=CarsTestDB;";
            NpgsqlConnection conn = new NpgsqlConnection(conStr);
            string comStr = "Select * FROM \"CarsTable\";";
            NpgsqlCommand com = new NpgsqlCommand(comStr, conn);
            NpgsqlDataAdapter ad = new NpgsqlDataAdapter(com);
            DataTable dt = new DataTable();
            Console.WriteLine("Conection to server established …
Run Code Online (Sandbox Code Playgroud)

c# database postgresql datasource npgsql

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

Unity:找不到UI布局元素的最大大小

在Unity UI中,LayoutElement具有最小,首选和固定大小,但没有max size属性。

例如,如果我有一个text1

layoutElement.flxibleWith = 1
layoutElement.minHeight  = 19
Run Code Online (Sandbox Code Playgroud)

text1 一行txt:

具有一行txt的text1

但是,当我在text1其中加载文本时,它的高度会无限扩展:

在此处输入图片说明

我已经编写了一个脚本:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

[ExecuteInEditMode]
[RequireComponent(typeof(LayoutElement))]

public class LayoutElementMaxSize : MonoBehaviour
{

private LayoutElement layoutElement;
private ContentSizeFitter contentSizeFitter;
private RectTransform rectransform;

public bool controllWidth;
public bool controllHeight;

public float maxHight;
public float maxWidth;

void Start()
{
    layoutElement = GetComponent<LayoutElement>();
    rectransform = GetComponent<RectTransform>();
}

public void Update()
{
    if(rectransform.hasChanged)
     {
        rectransform.hasChanged = false;

        if (controllHeight)
        {
            layoutElement.preferredHeight = -1;

            layoutElement.CalculateLayoutInputHorizontal();
            layoutElement.CalculateLayoutInputVertical(); …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine unity3d-2dtools

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

使用Linq循环遍历所有控件只能获得第一个控件

我有一个带有5个文本框和一个按钮的表单,我想检查所有这些文本框是否为空或空用户输入.使用这个简单的方法:

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (verifyUI() == true)
                MessageBox.Show("user input for all textboxes was correct!");
            else
                MessageBox.Show("user input for all textboxes was missing!");
        }

        private bool verifyUI()
        {
            bool userInputOk = false;
            foreach (Control cTxt in Controls.OfType<TextBox>())
            {
                if (string.IsNullOrWhiteSpace(cTxt.Text) || cTxt.Text == "")
                {
                    userInputOk = false;
                }
                else
                {
                    userInputOk = true;
                }
            }
            return userInputOk;
        }
    }
Run Code Online (Sandbox Code Playgroud)

当我在文本框1中输入值时,该方法仅检查第一个文本框并返回true,并忽略所有其他文本框.

我确信我正在使用的方法的逻辑有问题.

c# linq

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

使用 HTML 特殊字符代码与直接粘贴特殊代码

哪种做法被认为是更好的做法,以及为什么它会产生什么影响:

在网页中使用特殊字符 HTML 代码(例如&copy;为了版权)或直接使用Character Map并复制粘贴符号到页面中。

更具体地说,在什么情况下不建议使用html 文字?

html markup parsing ascii character-encoding

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