是否有另一种方法可以删除命令内部的空格?

发布于 2025-01-29 18:09:07 字数 581 浏览 3 评论 0原文

这是我的代码:

cmd.CommandText = "SELECT Stud_ID, LCase(Stud_Fname)&LCase(Stud_Lname) AS name FROM tbl_Student";
            OleDbDataReader reader1 = cmd.ExecuteReader();
            while (reader1.Read()){
                Console.WriteLine(reader1[1].ToString());
            }
            reader1.Close();

我想实现的预期投票是在此处输入图像描述 Stud_fname和lname将组合,并且将是小写。但是我的问题是,我需要用2个给定名称(例如Dela Cruz)删除名称之间的空格。应该是Delacruz。我尝试的是.replace();和.trim()但行不通的人可以帮助我。建议我该怎么办?

This is my code:

cmd.CommandText = "SELECT Stud_ID, LCase(Stud_Fname)&LCase(Stud_Lname) AS name FROM tbl_Student";
            OleDbDataReader reader1 = cmd.ExecuteReader();
            while (reader1.Read()){
                Console.WriteLine(reader1[1].ToString());
            }
            reader1.Close();

The expected out put that I want to achieve was enter image description here the Stud_Fname and Lname will combine and it will be as lowerCase. but my problem was I need to removed the whitespace between the name with 2 given name such as Dela Cruz. It should be delacruz . What I tried is the .Replace(); and .Trim() but it didn't work can someone help me. suggest what should I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨后咖啡店 2025-02-05 18:09:07

替换应该有效:

cmd.CommandText = "SELECT Stud_ID, LCase(Replace(Stud_Fname, ' ', '') & LCase(Stud_Lname) AS name FROM tbl_Student";

Replace should work:

cmd.CommandText = "SELECT Stud_ID, LCase(Replace(Stud_Fname, ' ', '') & LCase(Stud_Lname) AS name FROM tbl_Student";
厌倦 2025-02-05 18:09:07

这对我有用:

private void button1_Click(object sender, EventArgs e)
{
    using (OleDbConnection conn = new OleDbConnection(Properties.Settings.Default.AccessTest))
    {
        string strSQL =
            "SELECT ID, Firstname, LastName, Active," +
            "Replace(lcase([Firstname]) & lcase([LastName]),' ','') as FullName FROM tblPeople";

        using (OleDbCommand cmdSQL = new OleDbCommand(strSQL, conn))
        {
            conn.Open();
            DataTable rstData = new DataTable();
            rstData.Load(cmdSQL.ExecuteReader());
            dataGridView1.DataSource = rstData;
        }
    }
}

因此,我们以名字或姓氏为单位删除所有空间。

This works for me:

private void button1_Click(object sender, EventArgs e)
{
    using (OleDbConnection conn = new OleDbConnection(Properties.Settings.Default.AccessTest))
    {
        string strSQL =
            "SELECT ID, Firstname, LastName, Active," +
            "Replace(lcase([Firstname]) & lcase([LastName]),' ','') as FullName FROM tblPeople";

        using (OleDbCommand cmdSQL = new OleDbCommand(strSQL, conn))
        {
            conn.Open();
            DataTable rstData = new DataTable();
            rstData.Load(cmdSQL.ExecuteReader());
            dataGridView1.DataSource = rstData;
        }
    }
}

So, we remove all spaces - in first or last name.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文