miércoles, 28 de noviembre de 2018
día de la semana
Dim i As Integer = DateTime.Now.DayOfWeek
cambiar db_owner a dbo
ejemplo:
tabla: db_owner.clientes
ALTER SCHEMA dbo TRANSFER db_owner.clientes
tabla: dbo.clientes
tabla: db_owner.clientes
ALTER SCHEMA dbo TRANSFER db_owner.clientes
tabla: dbo.clientes
martes, 27 de noviembre de 2018
jueves, 22 de noviembre de 2018
nombre del archivo
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Dim nombre As String = "DTE(id_DTE)100.xyz(0001).xml"
Dim nombre As String = "DTE(tipo_DTE)(folio).(x)xml"
Dim x As New ArrayList
Dim dato As String = ""
Dim n As Integer = nombre.Length ' 28
Dim j As Integer = 0
Dim k As Integer = 0
For i As Integer = 0 To nombre.Length - 1
If nombre(i) = "(" Then
For j = i To nombre.Length - 1
dato += nombre(j)
If nombre(j) = ")" Then
x.Add(dato)
dato = ""
i = j
Exit For
End If
Next
Else
For k = i To nombre.Length - 1
If nombre(k) = "(" Then
x.Add(dato)
i = k - 1
dato = ""
Exit For
Else
dato += nombre(k)
i = k
If i = nombre.Length - 1 Then
x.Add(dato)
i = k
dato = ""
Exit For
End If
End If
Next
End If
Next
MessageBox.Show("!")
End Sub
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Dim nombre As String = "DTE(id_DTE)100.xyz(0001).xml"
Dim nombre As String = "DTE(tipo_DTE)(folio).(x)xml"
Dim x As New ArrayList
Dim dato As String = ""
Dim n As Integer = nombre.Length ' 28
Dim j As Integer = 0
Dim k As Integer = 0
For i As Integer = 0 To nombre.Length - 1
If nombre(i) = "(" Then
For j = i To nombre.Length - 1
dato += nombre(j)
If nombre(j) = ")" Then
x.Add(dato)
dato = ""
i = j
Exit For
End If
Next
Else
For k = i To nombre.Length - 1
If nombre(k) = "(" Then
x.Add(dato)
i = k - 1
dato = ""
Exit For
Else
dato += nombre(k)
i = k
If i = nombre.Length - 1 Then
x.Add(dato)
i = k
dato = ""
Exit For
End If
End If
Next
End If
Next
MessageBox.Show("!")
End Sub
End Class
miércoles, 14 de noviembre de 2018
xmloptions
Imports System.Xml
Public Class Form1
Public archivo As String = "cfg.xml"
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
Dim doc As New XmlDocument
doc.Load(archivo)
Dim tablas As XmlNodeList = doc.SelectNodes("/Data/TCV/tabla") ' cargar tablas
Dim campos As XmlNodeList = doc.SelectNodes("/Data/TCV/campo/id") ' cargar todos los campos
For Each x As XmlNode In campos
MessageBox.Show(x.InnerXml)
Next
End Sub
Private Sub btnvervar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvervar.Click
Dim campo As String = "test2"
Dim doc As New XmlDocument
doc.Load(archivo)
Dim nodes As XmlNodeList = doc.SelectNodes("/Data/TCV")
For Each x As XmlNode In nodes
Dim nodevar As XmlNodeList = x.SelectNodes("campo/id")
For Each node As XmlNode In nodevar
If node.InnerXml = campo Then
Dim var As XmlNodeList = node.ParentNode.SelectNodes("variables/var")
For Each elem As XmlNode In var
MessageBox.Show(elem.InnerXml)
Next
Exit For
End If
Next
Next
End Sub
Private Sub btneliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneliminar.Click
Dim tabla As String = "DoctosFE"
Dim doc As New XmlDocument
doc.Load(archivo)
Dim xpath As String = "/Data/TCV[tabla=""" & tabla & """]"
Dim del As XmlElement = doc.SelectSingleNode(xpath)
del.ParentNode.RemoveChild(del)
doc.Save(archivo)
End Sub
Public Class Form1
Public archivo As String = "cfg.xml"
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
Dim doc As New XmlDocument
doc.Load(archivo)
Dim tablas As XmlNodeList = doc.SelectNodes("/Data/TCV/tabla") ' cargar tablas
Dim campos As XmlNodeList = doc.SelectNodes("/Data/TCV/campo/id") ' cargar todos los campos
For Each x As XmlNode In campos
MessageBox.Show(x.InnerXml)
Next
End Sub
Private Sub btnvervar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvervar.Click
Dim campo As String = "test2"
Dim doc As New XmlDocument
doc.Load(archivo)
Dim nodes As XmlNodeList = doc.SelectNodes("/Data/TCV")
For Each x As XmlNode In nodes
Dim nodevar As XmlNodeList = x.SelectNodes("campo/id")
For Each node As XmlNode In nodevar
If node.InnerXml = campo Then
Dim var As XmlNodeList = node.ParentNode.SelectNodes("variables/var")
For Each elem As XmlNode In var
MessageBox.Show(elem.InnerXml)
Next
Exit For
End If
Next
Next
End Sub
Private Sub btneliminar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btneliminar.Click
Dim tabla As String = "DoctosFE"
Dim doc As New XmlDocument
doc.Load(archivo)
Dim xpath As String = "/Data/TCV[tabla=""" & tabla & """]"
Dim del As XmlElement = doc.SelectSingleNode(xpath)
del.ParentNode.RemoveChild(del)
doc.Save(archivo)
End Sub
martes, 13 de noviembre de 2018
transformar de arraylist a array
Dim array As new Arraylist
array.ToArray(GetType(System.String))
array.ToArray(GetType(System.String))
editar eliminar nodos xml
Imports System.Xml
Public Class Form1
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
Dim doc As New XmlDocument
doc.Load("archivo.xml")
'For Each node As XmlNode In doc.GetElementsByTagName("tcv")
' 'MessageBox.Show(node.OuterXml)
' If node.Name = "folio" Then
' MessageBox.Show("!")
' End If
'Next
Dim nodes As XmlNodeList = doc.SelectNodes("data/tcv")
For Each node As XmlNode In nodes
'MessageBox.Show("TAbla:" & node("tabla").InnerText & " " & "campo:" & node("campo").InnerText)
Dim str As String = node.OuterXml
'Dim x As XmlElement = node.ParentNode
doc.LoadXml(str)
Dim varnodes As XmlNode = doc.SelectSingleNode("tcv/variables")
'MessageBox.Show(node.OuterXml)
Next
'doc.Save("archivo.xml")
End Sub
End Class
<?xml version="1.0" encoding="utf-8"?>
<data>
<tcv>
<tabla>hist_DTE</tabla>
<campo>tipo_DTE</campo>
<var1>mitipodte=33</var1>
</tcv>
<tcv>
<tabla>DTE_recibos</tabla>
<campo>folio</campo>
<variables>
<var>foliodeldte=68976</var>
<var>foliodeldte=68976</var>
</variables>
</tcv>
</data>
Public Class Form1
Private Sub btnok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnok.Click
Dim doc As New XmlDocument
doc.Load("archivo.xml")
'For Each node As XmlNode In doc.GetElementsByTagName("tcv")
' 'MessageBox.Show(node.OuterXml)
' If node.Name = "folio" Then
' MessageBox.Show("!")
' End If
'Next
Dim nodes As XmlNodeList = doc.SelectNodes("data/tcv")
For Each node As XmlNode In nodes
'MessageBox.Show("TAbla:" & node("tabla").InnerText & " " & "campo:" & node("campo").InnerText)
Dim str As String = node.OuterXml
'Dim x As XmlElement = node.ParentNode
doc.LoadXml(str)
Dim varnodes As XmlNode = doc.SelectSingleNode("tcv/variables")
'MessageBox.Show(node.OuterXml)
Next
'doc.Save("archivo.xml")
End Sub
End Class
<?xml version="1.0" encoding="utf-8"?>
<data>
<tcv>
<tabla>hist_DTE</tabla>
<campo>tipo_DTE</campo>
<var1>mitipodte=33</var1>
</tcv>
<tcv>
<tabla>DTE_recibos</tabla>
<campo>folio</campo>
<variables>
<var>foliodeldte=68976</var>
<var>foliodeldte=68976</var>
</variables>
</tcv>
</data>
lunes, 12 de noviembre de 2018
Editar nodo xml
Public Sub guardar_conex(ByVal conex As String)
Dim nodo As String = "Data/Conex"
Dim doc As New XmlDocument
doc.Load(archivo.config)
doc.SelectSingleNode(nodo).InnerText = conex
doc.Save(archivo.config)
End Sub
Dim nodo As String = "Data/Conex"
Dim doc As New XmlDocument
doc.Load(archivo.config)
doc.SelectSingleNode(nodo).InnerText = conex
doc.Save(archivo.config)
End Sub
jueves, 8 de noviembre de 2018
extraer datos entre parentesis
Dim x As String = "campo()"
x = x.Split("(")(1)
x = x.TrimEnd(")")
x = x.Split("(")(1)
x = x.TrimEnd(")")
extraer dato entre paréntesis
dato(12345,5678)
Dim x() As String = dato.Split(New String() {"(", ")"}, StringSplitOptions.RemoveEmptyEntries)
R: 12345,5678
fuente
Obtener nombre de la base de datos
Public Function obtener_base_de_datos(ByVal conex As String) As String
Dim data() As String = conex.Split(";")
Return Array.Find(data, Function(x) x.ToString.Contains("Catalog")).Split("=")(1).Trim
End Function
Dim data() As String = conex.Split(";")
Return Array.Find(data, Function(x) x.ToString.Contains("Catalog")).Split("=")(1).Trim
End Function
cómo saber si una tabla existe
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'tabla'
miércoles, 7 de noviembre de 2018
Matchcollection to array
Dim matches As MatchCollection = Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
Dim tablas() As String = matches.Cast(Of Match).Select(Function(y As Match) y.Value).ToArray
Dim tablas() As String = matches.Cast(Of Match).Select(Function(y As Match) y.Value).ToArray
regex matches to array
Dim matches As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
Dim matches() As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)").Cast(Of System.Text.RegularExpressions.Match)().ToArray
For Each m As System.Text.RegularExpressions.Match In System.Text.RegularExpressions.Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
MsgBox(m.Value)
Next
Otro ejemplo
Dim lista_match As MatchCollection = Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
Dim x() As String = lista_match.Cast(Of Match).Select(Function(y As Match) y.Value).ToArray
Para extraer una sola tabla
Dim tabla_sql As String = System.Text.RegularExpressions.Regex.Match(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)").Value.Trim
fuente
Dim matches() As System.Text.RegularExpressions.Match = System.Text.RegularExpressions.Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)").Cast(Of System.Text.RegularExpressions.Match)().ToArray
For Each m As System.Text.RegularExpressions.Match In System.Text.RegularExpressions.Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
MsgBox(m.Value)
Next
Otro ejemplo
Dim lista_match As MatchCollection = Regex.Matches(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)")
Dim x() As String = lista_match.Cast(Of Match).Select(Function(y As Match) y.Value).ToArray
Para extraer una sola tabla
Dim tabla_sql As String = System.Text.RegularExpressions.Regex.Match(query, "(?<=from|join|FROM|JOIN)(\s+\w+\b)").Value.Trim
fuente
lunes, 5 de noviembre de 2018
valores de columna y verificar si hay valores fuera de rango
errores base de datos y reparar
DBCC CHECKDB ([nombre_base_de_datos])
base de datos en modo single user o multi user
SELECT user_access_desc FROM sys.databases WHERE name = 'nombre_base_de_datos'
fuente1
fuente2
Suscribirse a:
Entradas (Atom)