Save SQL Script into Resources

  • Thread starter Thread starter Shai Goldberg
  • Start date Start date
S

Shai Goldberg

Hi,

Is there a way to store an SQL script into a resource
file, the script contains a lot of lines, and then to
read it during run-time into a string?

Thanks,
 
Hi Shai
Is there a way to store an SQL script into a resource
file, the script contains a lot of lines, and then to
read it during run-time into a string?

Why not,

Or do you mean what is the best way, I think there is no best way, that
depends in what kind of environment you want to use it.

If you tell that a little more, than maybe we can help you?

Cor
 
* "Shai Goldberg said:
Is there a way to store an SQL script into a resource
file, the script contains a lot of lines, and then to
read it during run-time into a string?

Add the file to the project, set its 'Build Action' to 'Embedded
Resource', then:

\\\
Imports System.IO
..
..
..
Dim f As Stream =
System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceStream( _
"<Name of the root namespace>.test.txt" _
)
Dim st As New StreamReader(f), s As String
s = st.ReadToEnd()
MsgBox(s)
///
 
Hi,

I need to add a text file into a source file and to be
able to read it during run time using VB.NET

I want to know if there is a way to do so using the
VS.NET IDE and VB.NET that is to insert into a source
file a bunch of text lines that I can read into a string
during run time.

Thanks,
 
Thanks for the answer but it didn't help me, maybe I just
didn't understand, but I need to load a lot of lines and
not only one single line.

Regards,
 
Hi Shai,

I saw you did get some answers in this thread if that does not fit, message
again OK?

Cor
 
Hi,

Is there a way to store an SQL script into a resource
file, the script contains a lot of lines, and then to
read it during run-time into a string?

Thanks,



Hi,

You can use streamreader function to read the sql text, and after that can
you make a split on 'GO'. after that can you execute the the different
parts in the script. (you can not execute the hole script including GO,
because it isnt allowed)

Thomas
 
Hi Shai,

I saw you other message, the most easiest way is to make a dataset,

I made some examples below. I did not make in the IDE so it is probably with
errors.

I think this wil fits your problem?

Cor

\\\\
dim ds as new dataset
if file.exist ("c:\test1\testxml.xml") then
ds.ReadXml("c:\testxml.xml", XmlReadMode.ReadSchema)
Dim dr As DataRow = ds.Tables(0).Rows.Find("mynumber")
if not dr Is Nothing Then
mySQLstring = dr.item("mySqlString").tostring
else
'errormessage
Else
'errormessage
End If
////
\\\\
To create this dataset is.
dim ds as new dataset
Dim dt As New DataTable("SqlStrings")
dt.Columns.Add(New DataColumn("mySqlStringnumber",
Type.GetType("System.Int32")))
dt.Columns.Add(New DataColumn("mySqlString", Type.GetType("System.String")))
Dim keys(0) As DataColumn
keys(0) = dt.Columns("mySqlStringnumber")
dt.PrimaryKey = keys
ds.Tables.Add(dt)
ds.WriteXml("c:\testxml.xml", XmlWriteMode.WriteSchema)
///
\\\
To add the rows you can use the normal dataset instructions for that
////
 
Shai Goldberg said:
Thanks for the answer but it didn't help me, maybe I just
didn't understand, but I need to load a lot of lines and
not only one single line.

Resources are not limited to a single line.
 
Herfried hi,

I wanted to thank you for your solution, it was what I
was looking for!

I want also to thank all that tried to help me.

Regrads,
-----Original Message-----


Add the file to the project, set its 'Build Action' to 'Embedded
Resource', then:

\\\
Imports System.IO
..
..
..
Dim f As Stream =
System.Reflection.Assembly.GetEntryAssembly
().GetManifestResourceStream( _
 
Back
Top