本文介绍了如何使用checklistbox来创建SQL合并删除语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢Richard,我能够允许用户点击checklistbox项目并在vb.net中创建sql表时使用它们。所以,我试着采用他的一个很棒的例子并以类似的方式使用它。到目前为止,这里是我所拥有的:



So Thanks to Richard I was able to allow users to click on checklistbox items and use them in the creation of an sql table inside vb.net. SO, I tried to take his awesome example and use it in a similar way. so far here is what I have:

Dim cb As New System.Text.StringBuilder("MERGE INTO")
       Dim tableName As String = ListBox1.SelectedItems(Convert.ToString(tableName))
       Dim tablename2 As String = ListBox2.SelectedItems(Convert.ToString(tablename2))
       cb.AppendFormat(" [{0}] ", tableName.Replace("]", "]]"))
       cb.Append("as T")
       cb.AppendFormat(" using [{0}] ", tablename2.Replace("]", "]]"))
       cb.Append("As S")
       '   cb.AppendFormat(", [{0}] nvarchar(max) NULL", tableName.Replace("]", "]]"))

       For Each item In CheckedListBox1.CheckedItems
           Dim columnName As String = Convert.ToString(item)
           cb.AppendFormat("on T." + columnName.Replace("]", "]]") + "[{0}]S." + columnName.Replace("]", "]]"))
       Next
       cb.Append(")")

       Dim sql As String = cb.ToString()

       sqlcon.Open()
       Dim cmd As SqlClient.SqlCommand
       cmd = New SqlClient.SqlCommand(sql, sqlcon)

       cmd.ExecuteNonQuery()
       sqlcon.Close()





这里是我试图使用此代码的sql语句:





here is the sql statement I am trying to work into this code:

Merge into table1 as T
using [table] as S
on T.[Last Name] = S.[Last Name] and T.[First Name] = S.[First Name]

When Matched then
Update Set T.[age] = S.[age];

DELETE T1 FROM [table] T1 JOIN [table1] T2 ON T1.[Last Name] = T2.[Last Name] AND T1.[First Name] = T2.[First name];





我需要帮助才能完成这项任务。我在使用ands时遇到了困难,并且我开始使用新的字符串构建器匹配和删除?



我尝试过:



我已经替换了多个字符以使sql字符串准确。



I am needing help working this in. I am having a hard time with the ands and do I start a new string builder for the when matched and delete from?

What I have tried:

I have replaced multiple characters to make the sql string accurate.

推荐答案


这篇关于如何使用checklistbox来创建SQL合并删除语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 06:56
查看更多