|
hi i have to insert a string into database but while inserting it is not allowing me to insert as ther is some special characters and my main problem is string contains ( ' ) this character .i am in need of escape characters in vb.net
thanks
with regards
Balagurunathan.B
|
|
|
|
|
Hi,
You can try Asc(27) or Char(Asc(27)) or Char("ESC") .
Good luck,
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
HI
SHOULD I HAVE TO REPLACE COMMAND
I NEE THE ORIGINAL CONTENTS BACK WHILE RETRIVING
IN C# WE USE \\ R @ CHAR WAT HAVE TO USE FOR THIS
with regards
Balagurunathan.B
|
|
|
|
|
Hi Balagurunathan,
No need to shout, I can hear you just fine (please press your Caps Lock key).
It seems that I did not quite understand you. You are not looking to identify the Escape character but the ' character.
In VB.NET you can use the Replace method:
YourString.Replace("'", "´")
The first string is the string (or character) that you want to remove, and the second string is the string that you want to put in its place.
If you only want to remove a certain string or character from a String you could try:
YourString.Replace("'", "")
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
see i can use replace command for that but the thing is before storing i will concat the string by line by line as how the program will look so at that time i can replace it but while retriving it will be like a full program so now i am not able to replace
its the problem
so i am trying to use escape character
with regards
Balagurunathan.B
|
|
|
|
|
Where are you retrieving the text from, a database, a file or a TextBox?
My advice is free, and you may get what you paid for.
|
|
|
|
|
really its a program
i am reading line by line
i have to store some part of code into database so in some circumstance i will display those part to the endusers
some times i have to retrive values from buffer and have to store in database and have to display it later to enduser
for the purpose i need escape character which will store as it and so no need to replace again by searching and all
with regards
Balagurunathan.B
|
|
|
|
|
Hi,
I am sorry, I am trying to help you, but I am not sure what you mean.
Are you trying to read VB.NET code programmatically, and then insert it into a database?
Is the problem that the VB.NET code contains ' characters (comments in VB.NET)?
Does you application need to show existing code to a user, allow the user to modify the code, and if he wants, let the user save the modified code into the database?
In other words, the code may contain ' characters when you have to read it, and/or it may contain ' characters when you insert it (back) into a database?
Please can you clarify?
Johan
My advice is free, and you may get what you paid for.
|
|
|
|
|
hi
now i will say very clearly
i want to insert a string into database
for eg its a program and i am going to insert in a memo field
the string contains many spl char the single quotes is my big problem( ' )
i want to use some escape char so i can save asit into databse and retrive the content simillar to original string insert
in c# we use @ or \\ wat we will be using in vb.net
with regards
Balagurunathan.B
|
|
|
|
|
If you use a parameterized query, you don't have to worry about escaping this character yourself. The Parameter object will escape it, and many others, for you.
Read up on parameterized queries in Colin's article here[^].
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Well as far as i understand, u need to replace (') by ?('') (two single quotes) before storing it into database.
('') is nothing but the escape sequence for (') in Database (not i \n Vb.net).
I guess this will solve the problem.
"If our Mind can, the Program can !!"
|
|
|
|
|
Private Sub Form1_Closing(ByVal sender As Object, ByVal e _
As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
Dim a%
a = MsgBox("Save and close", MsgBoxStyle.YesNoCancel, )
If a = vbYes Then
MsgBox("yes")
ElseIf a = vbNo Then
MsgBox("no")
ElseIf a = vbCancel Then
MsgBox("Cancel")
End If
End Sub
--------------------------------------------------------------------------
What ever the option I choose the form closes eventually. even if I choose cancel the form closes, is there a way to stop this?
(Yes - file saved then closed)
(No - close without saving)
(Cancel - Cancel)-I don't want the form to close when choosing Cancel.
Pls reply.
Ps
this website Rocks!!!
|
|
|
|
|
Because primarily you have called Form's closing event what is getting initiated to get close the form. In vb.net there is a statement as me.close what closes the form.
Try to use your code out of Form's closing event. In the mean while, try to add "exit sub" where ever you cancel it process.
I hope that helps
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
If you want the form not to close then you need to add:
e.Cancel = True
This is the correct event to do this type of thing.
Ben
|
|
|
|
|
No! because you have already being initiated to form's close event. Eventually it will close it. You can have some codes inside the form's close event but, it will close the form after processing the tasks.
I think you are using VB6 not VB.net therefore I don't remember if there was a statement like e.cancel for closing form.
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
My code is for vb.net and it does work. If this is a vb6 question then I missed that.
Ben
|
|
|
|
|
Here's a link to some microsoft help on this event in vb.net and using the e.Cancel = True
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/CPref17/html/M_System_Windows_Forms_Form_OnClosing_1_84f7c28c.htm
Ben
|
|
|
|
|
If you are using vb.net and
you want the form not to close then you need to add:
e.Cancel = True
This is the correct event to do this type of thing.
Ben
|
|
|
|
|
|
how to get text of selected item in listview?
Please help....
|
|
|
|
|
ListBox1.SelectedItem ' gets or sets teh selected items in listbox
Listbox1.SelectedIndex ' gets the selected item's index number in listbox
Try!
What a curious mind needs to discover knowledge is noting else than a pin-hole.
|
|
|
|
|
how to create sql database in with userdefined name at runtime through vb.net
|
|
|
|
|
Create a connection to the master database on the SQL Server.
Create a SqlCommand that issues the CREATE DATABASE command (see SQL Books on line for details - I've no idea of your situation and I'm not going to second guess).
Then you ExecuteNonQuery on the command.
If the create command worked then you can now connect to your new database.
|
|
|
|
|
about this I have already tried out this it woks well if the database is in sql 2000 but if the database is to be created in sql 2005 it does not allow.
to solve the problem i have tried out many way but could not get it so can explain with some example.
thanx for the support
taher
|
|
|
|
|
Well try using "SQLDMO" dll
This code worked for SQL 2000.
Some code -
Imports System.Data.SqlClient
Imports SQLDMO
'Lists available servers
Private oSqlServer As New SQLDMO.SQLServer
Dim sqlDmoApplication As New SQLDMO.Application
Dim serverList As SQLDMO.NameList
serverList = sqlDmoApplication.ListAvailableSQLServers()
'Create Database
Private Function createDB() As Boolean
Dim oDatabase As SQLDMO.Database
Dim oDBFileData As SQLDMO.DBFile
Dim oLogFile As SQLDMO.LogFile
oDatabase = New Database
oDBFileData = New DBFile
oLogFile = New LogFile
Try
'Delete Database if it exists
Call connectDB()
'If Not IsNothing(oSqlServer.Databases.Item(txtDBName.Text.Trim())) Then
'oSqlServer.Databases.Item(DBToCreate).Remove()
'Response.Write("Database with same name already exists")
'End If
For i As Integer = 1 To oSqlServer.Databases.Count
If txtDBName.Text.Trim().ToUpper = oSqlServer.Databases.Item(i).Name.Trim.ToUpper() Then
lblAlert.Text = ("Database with same name already exists, please mention different name")
Return False
End If
Next
oDatabase.Name = txtDBName.Text.Trim() '"SOM_DB"
' Define the PRIMARY data file.
oDBFileData.Name = txtDBName.Text.Trim() & "Data"
' Replace the following path with your own path to a database folder.
oDBFileData.PhysicalName = "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\" & txtDBName.Text.Trim() & "_DB.mdf"
oDBFileData.PrimaryFile = True
' Specify file growth in chunks of fixed size for all data files.
oDBFileData.FileGrowthType = SQLDMO.SQLDMO_GROWTH_TYPE.SQLDMOGrowth_MB
oDBFileData.FileGrowth = 1
oDatabase.FileGroups.Item("PRIMARY").DBFiles.Add(oDBFileData)
' Define the database transaction log.
oLogFile.Name = txtDBName.Text.Trim() & "Log1"
' Replace the following path with your own path to a database folder.
oLogFile.PhysicalName = "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\" & txtDBName.Text.Trim() & "_DB.ldf"
oDatabase.TransactionLog.LogFiles.Add(oLogFile)
oSqlServer.Databases.Add(oDatabase)
oDatabase = Nothing
oDBFileData = Nothing
oLogFile = Nothing
Return True
Catch ex As Exception
lblAlert.Text = "Error : " & ex.Message()
Return False
End Try
End Function
"If our Mind can, the Program can !!"
|
|
|
|