Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Pure VPN - Up to 27 Months
vgp
Updated:
Today at 8:10 AM
එක පැකේජ් එකයි මාසෙටම Unlimited Internet. තාමත් DATA CARD දාන්න සල්ලි වියදම් කරනවද? අඩුම මිලට අපෙන්.
sayuru bandara
Updated:
Tuesday at 12:30 PM
Ad icon
ඉන්ටර්නෙට් එකෙන් හරියටම සල්ලි හොයන්න සහ Success වෙන්න කැමතිද? 🚀 (E-Money & Success Stories)
siri sumana
Updated:
Saturday at 11:44 PM
Gemini AI PRO 18 months Offer
Hawaka
Updated:
May 27, 2026
Ad icon
koko account
DasunEranga
Updated:
May 27, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Help
VB6 HELP ME, Database
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="Ranhiru" data-source="post: 5801645" data-attributes="member: 17748"><p>Visual Basic .NET 2008 thama machan use karanne</p><p></p><p><span style="font-family: 'Arial'"><span style="font-size: 10px">'first creating a Sql Connection ... put this in a module so it will be global</span></span></p><p> <span style="font-family: 'Arial'"><span style="font-size: 10px">'Put any valid Sql Connection String.. Get Connection Strings from <a href="http://www.connectionstrings.com/" target="_blank">http://www.connectionstrings.com</a></span></span></p><p></p><p>Me thiyenne SQL Server walata...i think what you need for a connection string is </p><p><a href="http://connectionstrings.com/access-2007" target="_blank">http://connectionstrings.com/access-2007</a></p><p> </p><p> </p><p> [CODE]Public connection As New SqlConnection("Persist Security Info=False;Data Source="|DataDirectory|Database1.sdf")[/CODE] <span style="font-family: 'Arial'"><span style="font-size: 10px"><u><strong>Getting A set of data from a Sql Database</strong></u></span></span></p><p> </p><p>[CODE]Dim dt As New DataTable()</p><p>Dim ds As New DataSet</p><p> </p><p> Dim queryString As String = "SELECT * FROM Country ORDER BY CCode"</p><p>Dim adapter As SqlCeDataAdapter = New SqlCeDataAdapter(queryString, connection)</p><p>adapter.FillLoadOption = LoadOption.OverwriteChanges</p><p></p><p> adapter.Fill(ds, "Country")</p><p> </p><p> dt = ds.Tables("Country")</p><p>[/CODE] <span style="font-family: 'Arial'"><span style="font-size: 10px">'Now DataTable dt contains all the rows from the table Country</span></span></p><p> </p><p> </p><p> </p><p> <span style="font-family: 'Arial'"><span style="font-size: 10px"><strong><u>Getting a Single Data from the Database</u></strong></span></span></p><p> </p><p> <span style="font-family: 'Arial'"><span style="font-size: 10px">'This is a sample function written to get a Username when the User gives a UserID</span></span></p><p> <span style="font-family: 'Arial'"><span style="font-size: 10px">'connection should be defined first in the module or somewhere <img src="/styles/default/xenforo/smilies/default/D.gif" class="smilie" loading="lazy" alt=":D" title="Big grin :D" data-shortname=":D" /></span></span></p><p> </p><p> </p><p> [CODE] Function getUsername(ByVal UserID as Integer) As String</p><p> </p><p> Dim Username As String</p><p> </p><p> </p><p> Try</p><p> </p><p> connection.Open()</p><p> </p><p> Dim Command As New SqlCeCommand("SELECT Username FROM UserTable WHERE UserID=" & UserID, connection) </p><p> Username= Command.ExecuteScalar().ToString</p><p> </p><p> connection.Close()</p><p> </p><p> Return Username</p><p></p><p> </p><p> Catch ex As Exception</p><p> </p><p> End Try</p><p> </p><p> </p><p> End Function</p><p> </p><p>[/CODE] <span style="font-family: 'Arial'"><span style="font-size: 10px"><strong><u>Adding Data to the Database</u></strong></span></span></p><p> </p><p> <span style="font-family: 'Arial'"><span style="font-size: 10px">'This enters data in to a User Table</span></span></p><p> </p><p> [CODE] </p><p> Try</p><p> </p><p> Dim stringAdd As String = "INSERT INTO UserTable (" & txtUserID.Text & ",' " & txtUsername.Text & " ')"</p><p> </p><p> MsgBox(stringAdd)</p><p> 'MsgBox will display something like "INSERT INTO UserTable (0001,'Pradeep ElaKiri') "</p><p> </p><p> </p><p> Dim obj As New SqlCommand(stringAdd, connection)</p><p> </p><p> obj.Connection.Open()</p><p> obj.ExecuteNonQuery()</p><p> obj.Connection.Close()</p><p> </p><p> obj.Dispose()</p><p> </p><p> Catch ex As Exception</p><p> </p><p> MsgBox(ex.Message)</p><p> End Try</p><p>[/CODE] <span style="font-family: 'Arial'"><span style="font-size: 10px"><strong><u>Updating Data</u></strong></span></span></p><p> </p><p> [CODE] Dim stringUPDATE As String = "UPDATE UserTable SET Username=' " & txtNewUsername.Text & " ' WHERE UserID=" & txtUserID.Text </p><p> </p><p> MsgBox(stringUPDATE)</p><p> 'MsgBox should display something like "UPDATE UserTable SET Username='Naps' WHERE UserID=1"</p><p> </p><p> Dim obj As New SqlCommand(stringUPDATE, connection)</p><p> </p><p> </p><p> Try</p><p> </p><p> </p><p> obj.Connection.Open()</p><p> obj.ExecuteNonQuery()</p><p> </p><p> </p><p> </p><p> Catch ex As Exception</p><p> </p><p> MsgBox(ex.Message)</p><p> </p><p> </p><p> Finally</p><p> </p><p> obj.Connection.Close()</p><p> </p><p> obj.Dispose()</p><p> </p><p> End Try</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="Ranhiru, post: 5801645, member: 17748"] Visual Basic .NET 2008 thama machan use karanne [FONT=Arial][SIZE=2]'first creating a Sql Connection ... put this in a module so it will be global[/SIZE][/FONT] [FONT=Arial][SIZE=2]'Put any valid Sql Connection String.. Get Connection Strings from [URL="http://www.connectionstrings.com/"]http://www.connectionstrings.com[/URL][/SIZE][/FONT] Me thiyenne SQL Server walata...i think what you need for a connection string is [url]http://connectionstrings.com/access-2007[/url] [CODE]Public connection As New SqlConnection("Persist Security Info=False;Data Source="|DataDirectory|Database1.sdf")[/CODE] [FONT=Arial][SIZE=2][U][B]Getting A set of data from a Sql Database[/B][/U][/SIZE][/FONT] [CODE]Dim dt As New DataTable() Dim ds As New DataSet Dim queryString As String = "SELECT * FROM Country ORDER BY CCode" Dim adapter As SqlCeDataAdapter = New SqlCeDataAdapter(queryString, connection) adapter.FillLoadOption = LoadOption.OverwriteChanges adapter.Fill(ds, "Country") dt = ds.Tables("Country") [/CODE] [FONT=Arial][SIZE=2]'Now DataTable dt contains all the rows from the table Country[/SIZE][/FONT] [FONT=Arial][SIZE=2][B][U]Getting a Single Data from the Database[/U][/B][/SIZE][/FONT] [FONT=Arial][SIZE=2]'This is a sample function written to get a Username when the User gives a UserID[/SIZE][/FONT] [FONT=Arial][SIZE=2]'connection should be defined first in the module or somewhere :D[/SIZE][/FONT] [CODE] Function getUsername(ByVal UserID as Integer) As String Dim Username As String Try connection.Open() Dim Command As New SqlCeCommand("SELECT Username FROM UserTable WHERE UserID=" & UserID, connection) Username= Command.ExecuteScalar().ToString connection.Close() Return Username Catch ex As Exception End Try End Function [/CODE] [FONT=Arial][SIZE=2][B][U]Adding Data to the Database[/U][/B][/SIZE][/FONT] [FONT=Arial][SIZE=2]'This enters data in to a User Table[/SIZE][/FONT] [CODE] Try Dim stringAdd As String = "INSERT INTO UserTable (" & txtUserID.Text & ",' " & txtUsername.Text & " ')" MsgBox(stringAdd) 'MsgBox will display something like "INSERT INTO UserTable (0001,'Pradeep ElaKiri') " Dim obj As New SqlCommand(stringAdd, connection) obj.Connection.Open() obj.ExecuteNonQuery() obj.Connection.Close() obj.Dispose() Catch ex As Exception MsgBox(ex.Message) End Try [/CODE] [FONT=Arial][SIZE=2][B][U]Updating Data[/U][/B][/SIZE][/FONT] [CODE] Dim stringUPDATE As String = "UPDATE UserTable SET Username=' " & txtNewUsername.Text & " ' WHERE UserID=" & txtUserID.Text MsgBox(stringUPDATE) 'MsgBox should display something like "UPDATE UserTable SET Username='Naps' WHERE UserID=1" Dim obj As New SqlCommand(stringUPDATE, connection) Try obj.Connection.Open() obj.ExecuteNonQuery() Catch ex As Exception MsgBox(ex.Message) Finally obj.Connection.Close() obj.Dispose() End Try [/CODE] [/QUOTE]
Insert quotes…
Verification
Hath warak paha keeyada? (hatha wadikireema paha)
Post reply
Top
Bottom