Брайан Хупер: Вы почти достигли точки, но у вас есть ошибка в вашем синакс. Ваша вставка никогда не будет работать. Я тестировал свою базу данных, и вот правильный ответ:
INSERT INTO podatki (datum,ura,meritev1,meritev1_sunki,impulzi1,meritev2,meritev2_sunki,impulzi2)
SELECT '$datum', '$ura', '$meritve1','$sunki1','$impulzi1','$meritve2','$sunki2','$impulzi2'
FROM dual
WHERE NOT EXISTS (SELECT datum,ura
FROM podatki
WHERE datum='$datum' and ura='$ura'
Я даю вам мой пример таблицы y. Вставка почти такая же, как писал Биан Хупер, за исключением того, что я помещаю select FROM DUAL ont из другой таблицы. С уважением, Иван
Этот образец показывает, как считать и записать строку в MemoryStream.
<час>Imports System.IO
Module Module1
Sub Main()
' We don't need to dispose any of the MemoryStream
' because it is a managed object. However, just for
' good practice, we'll close the MemoryStream.
Using ms As New MemoryStream
Dim sw As New StreamWriter(ms)
sw.WriteLine("Hello World")
' The string is currently stored in the
' StreamWriters buffer. Flushing the stream will
' force the string into the MemoryStream.
sw.Flush()
' If we dispose the StreamWriter now, it will close
' the BaseStream (which is our MemoryStream) which
' will prevent us from reading from our MemoryStream
'sw.Dispose()
' The StreamReader will read from the current
' position of the MemoryStream which is currently
' set at the end of the string we just wrote to it.
' We need to set the position to 0 in order to read
' from the beginning.
ms.Position = 0
Dim sr As New StreamReader(ms)
Dim myStr = sr.ReadToEnd()
Console.WriteLine(myStr)
' We can dispose our StreamWriter and StreamReader
' now, though this isn't necessary (they don't hold
' any resources open on their own).
sw.Dispose()
sr.Dispose()
End Using
Console.WriteLine("Press any key to continue.")
Console.ReadKey()
End Sub
End Module
Можно также использовать
Encoding.ASCII.GetString(ms.ToArray());
, я не делаю , думают , это менее эффективно, но я не мог поклясться ему. Это также позволяет Вам выбрать различное кодирование, тогда как с помощью StreamReader необходимо было бы определить это в качестве параметра.
используйте StreamReader, тогда можно использовать метод ReadToEnd , который возвращает строку.
Используя StreamReader для преобразования MemoryStream в Строку.
<Extension()> _
Public Function ReadAll(ByVal memStream As MemoryStream) As String
' Reset the stream otherwise you will just get an empty string.
' Remember the position so we can restore it later.
Dim pos = memStream.Position
memStream.Position = 0
Dim reader As New StreamReader(memStream)
Dim str = reader.ReadToEnd()
' Reset the position so that subsequent writes are correct.
memStream.Position = pos
Return str
End Function
Слегка измененная версия ответа Брайана позволяет дополнительно управлять запуском чтения. Это, по-видимому, самый простой метод. наверное, не самый эффективный, но простой в понимании и использовании.
Public Function ReadAll(ByVal memStream As MemoryStream, Optional ByVal startPos As Integer = 0) As String
' reset the stream or we'll get an empty string returned
' remember the position so we can restore it later
Dim Pos = memStream.Position
memStream.Position = startPos
Dim reader As New StreamReader(memStream)
Dim str = reader.ReadToEnd()
' reset the position so that subsequent writes are correct
memStream.Position = Pos
Return str
End Function