|
It's complaining that the SQL statement your using to do the update is incorrect.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hai,
I am new in vb.net. before this i'm using VB6.My question is,
how to insert (save) data from text file into database.
This is the senario:
data from text file is:-
123456789qwert
then, i want to save the data into database(name TEST) like this :-
a) 1234 -> field name ID
b) 56 -> field name IC
c) 789 -> field name KP
d) qwert -> field name Address.
In vb6 I used mid(temp x,x) to read the data from text file and insert into database but i have no idea how to do this in vb.net.
pls help me.
TQ
I'm just the beginner...
|
|
|
|
|
I had a little trouble getting started as well in vb.net, don't give up though!!
Try this
'add this to setup your sub
Private Sub YourWorkSub()
Dim oDB as ClsDb
Dim MyQuery as String
try
oDB = New ClsDb("YourServerNameOrIP", "YourDataBaseName")
MyQuery = "Selec into (field name ID,field name IC,field name KP,field name Address) Values(1234,56,789,'quert')"
oDB.ExecuteQuery(MyQuery)
catch e as Exception
MsgBox(e.Message)
EndTry
End Sub
'Add This part down as a class
Imports System.Data.SqlClient
Public Class ClsDb
Private m_sServerIP As String
Private m_sDatabase As String
Sub New(ByVal sServerIP As String, ByVal sDatabase As String)
m_sServerIP = sServerIP
m_sDatabase = sDatabase
End Sub
Private Function GetConnection() As SqlConnection
Dim oDBConn As SqlConnection = New SqlConnection("User ID=YourUserID;Pwd=yourpass;Data Source=" & m_sServerIP & ";Initial Catalog=" & m_sDatabase)
Try
oDBConn.Open()
Catch e As SqlException
Throw e
End Try
Return oDBConn
End Function
Public Sub ExecuteQuery(ByVal sQuery)
Dim oCmd As SqlCommand
Dim oConn As SqlConnection
Try
oConn = GetConnection()
oCmd = New SqlCommand(sQuery, oConn)
oCmd.Connection = oConn
oCmd.ExecuteNonQuery()
oConn.Close()
Catch e As SqlException
Throw e
End Try
End Sub
End Class
Hope This Helps Ya!!
|
|
|
|
|
Hi .TriGiggleMich Thanks for helping me.
Actully this is the case :-
Somebody email me a text file content data which i need to insert into database.The data must be insert into database based on the length that has been set.
1st three character insert into field name1.
4th and 5th character insert into filed name2.
Last time i'm using VB6 and this is my coding.
---------------------------
Dim rs As ADODB.Recordset
Dim SQL As String
Dim db As ADODB.Connection
Set db = New ADODB.Connection
db.CursorLocation = adUseClient
db.Open "Database connection"
Set rs = New ADODB.Recordset
SQL = "select * from database name "
rs.Open SQL, Cons, adOpenStatic, adLockOptimistic, adCmdText
CMD.Filter = "*.txt| *.txt|*.dat| *.dat "
CMD.ShowOpen
If CMD.CancelError = True Then
Exit Sub
End If
If (CMD.FileName <> "") Then
Text6 = Mid(CMD.FileName, 4)
End If
If (CMD.FileName = "") Then
Exit Sub
End If
Open CMD.FileName For Input As #1
Do Until EOF(1)
Screen.MousePointer = vbHourglass
Line Input #1, temp
rs.AddNew
rs!Q1 = Mid(temp, 1, 1)
rs!Q2 = Mid(temp, 4, 1)
rs.Update
Loop
Set rs = Nothing
rs.Close
Close #1
CMD.FileName = ""
Screen.MousePointer = vbDefault
-------------
Now I need to convert all this to VB.NET
I'm just the beginner... ;(
|
|
|
|
|
I have a text field where users can submit source code to my website. This field contain the mix of code and description. All source code will be enclosed within a special tag [CODE][/Code]
I am looking for the regular expression to do the following in VB.NET:
Replace all occurrences of [code] with <pre>
Replace all occurrences of [/code] with </pre>
Replace all linebreaks (vbCrLf) outside the [code][/code] blocks with <BR>
Replace all < inside the [code][/code] blocks with ∓
-- modified at 10:09 Saturday 24th February, 2007
|
|
|
|
|
<code>
Public Function Change_Text(ByVal strInText As String, ByVal strOutText As String) As Boolean
Dim strSubText As String
Dim intPos As Integer
Dim bolCode As Boolean = False
'Default as OK
Change_Text = True
'Clear output string
strOutText = ""
'Loop through string
Do Until strInText = ""
'Look for opening '['
If Mid(strInText, 1, 1) = "[" Then
'Find closing tag
intPos = InStr(2, strInText, "]")
'Extract content
strSubText = Mid(strInText, 2, intPos - 2)
'Skip text beyond end tag
strInText = Mid(strInText, intPos + 1)
'Check tag information....
Select Case UCase(strSubText)
Case "/CODE"
'Closing tag
strOutText += "</pre>"
'Flag outside code area
bolCode = False
Case "CODE"
'Opening tag
strOutText += "<pre>"
'Flag inside code area
bolCode = True
Case Else
'Unknown [] tag - Flag as error ...
Change_Text = False
End Select
ElseIf Mid(strInText, 1, 2) = vbCrLf Then
strInText = Mid(strInText, 3)
If bolCode Then
'Inside Code Tags
strOutText += "&mp;"
Else
'Outside Code Tags
strOutText += "<br>"
End If
Else
'Write character to output string...
strOutText += Mid(strInText, 1, 1)
End If
Loop
End Function
</code>
Call with ....
<code>
If Not Change_Text(TextBox.Text, strOutput) Then
TextBoxError.Text = "Invalid Information entered"
bolError = True
End If
</code>
Hope this helps....
|
|
|
|
|
Thank you. The above code will work, but I am looking for regular expression which can do the above in 1~3 lines and which would be nore efficient.
|
|
|
|
|
Is this easily done??
Thanks in advance
|
|
|
|
|
Hello,
I have a lot of controls and information to put on to one form. When this is run the form will be to big for the screen. This is the requirement so has to fit on one form.
Is there a way, maybe to add scroll bar to the form, or do something else?
Many thanks,
Steve
|
|
|
|
|
The forms don't have scrollbars. However you can immitate it with a panel object. I have explained below how to do this:
First, place a panel object on your form and set its size to form's size (Width and Height) or you can apply docking. Then in the Panel object's attributes enable the scrollbar for the panel object. And then place all other objects inside the panel object (Drag and Drop). That is how you can scroll and see all other controls inside a form.
Give a try... I hope that helps.
Journey
|
|
|
|
|
exactly u want to make yr form as big as u want ....
do one thing in property window turn the ' autoscroll' as TRUE.
then yr form will increase t the size accordin to yr buttons and textboxes....
try this out ..and lemme knw..
|
|
|
|
|
Perhaps you should consider using a tab control instead of a scrolling panel. That's what usually is used to get more into a form that there is room for, and in my opinion more user friendly.
---
single minded; short sighted; long gone;
|
|
|
|
|
Thanks for your response.
All your ideas are very good, and I will try all of them.
Thanks,
Steve
|
|
|
|
|
well i am through with dot net package...
and i have the acquaintance wid the technical approaches of dot net...
but being a beginner i come accross many small problems and errors which i dnt knw hw to resolve.
can anybody help in troubleshootin and giving me guiadance..
thanks..
regards..
|
|
|
|
|
.net comes with MSDN library where mostly you can find answers to your questions. I strongly suggest you to use MSDN. For example if you get an error message, type it in MSDN search box and then examine the given answers.
Journey
|
|
|
|
|
yeah m already folowing that procedure.....
and solves most of the problem by myself.
but still i need a guiadnce for advances troubleshooting in coding
|
|
|
|
|
What you should do is whenever you get stuck on something post the code here and someone should help.
Kevin
|
|
|
|
|
I am using SQL 2000 DataBase for backend. and VB.Net 2005 For Frontent. now i want to save image in database which is in Picture box. How i can do this. and how i can show it in Picture box Form database. Saved Image.
Please Help me.
Thanks & Regards
Form :-
Vikash Yadav
|
|
|
|
|
you can check :this article
It's in C# but should be clear enough.
|
|
|
|
|
Hi, I have a textbox and a listbox. All I want to do is, when I enter a letter (in the textchanged of the textbox I want to search that letter, from the Listbox.) This is just the same as the windows do when you want to search for something.
My problem is this .. because if I am searching for a film called "Platoon", I want to write all the of word Platoon not "P" and then "L" and the listbox indicates the word platoon. This is how i want to make it. Can anyone help me please??
Adrian De Battista - Web Designer, Web Programmer, Software Programmer From Malta. My Website .. www.MaltaTrade.org
|
|
|
|
|
ADY007 wrote: because if I am searching for a film called "Platoon", I want to write all the of word Platoon not "P" and then "L" and the listbox indicates the word platoon.
So, what is your problem ? You want to be able to enter an entire word before the filtering starts ?
ADY007 wrote: Web Designer, Web Programmer
IS this an ASP.NET app ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
no no .. i want the filter to begin when i enter a letter. When i enter "P" .. the listbox goas and highlits the Word "Platoon" if "Platoon" is the only word that begins with letter "P" for example. If theres another word then nevermind i will enter the second letter and the filter will search for a word that begins with "Pl".
You know what i mean?? thanks very mcuh
Adrian De Battista - Web Designer, Web Programmer, Software Programmer From Malta. My Website .. www.MaltaTrade.org
|
|
|
|
|
OK, so handle the keypress event, and iterate over your listbox Items collection, looking for one that starts with what has been typed, and set it's selected flag to true.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi Everyone I Have Got a problem here....I have four comboboxes and about seven textboxes that are all data bound. every thing works great except when i add a new record. then the comboboxes do not reconize the updated database untill after the form is regenerated. I have tried to re load the formload event but that doesnt work. I am using vb.net 2005 and a data tier any comments are welcome
|
|
|
|
|
You have to reload your dataset that the combo is bound to. Depending on what you're doing, you may also have to call ResetBindings on your BindingSource to get the controls bound to it to reread their values.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|