•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the VB.NET section within the Software Development category of DaniWeb, a massive community of 430,098 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,160 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our VB.NET advertiser: Programming Forums
Views: 2837 | Replies: 3
![]() |
•
•
Join Date: Nov 2007
Location: � Jogja �
Posts: 2,585
Reputation:
Rep Power: 11
Solved Threads: 235
Hi Kartikey...
first : i wanna say welcome in dani web...
second : you didn't show any effort from your program..
"We only give homework help to those who show effort"
so, when you post thread again please show the effort...effort can make all of people here to understand the problem. thx
...
if u want to insert or update you must to connect vb.net with sql server 2000.
for better (my opinion) u can use module so u can call every time in all form..
this code for connection module :
this following code to insert data in database :
you can write the update code by your self and post a new thread if you get the problem..
ok..
all for the best..
NB : don't forget to reply the feedback
first : i wanna say welcome in dani web...
second : you didn't show any effort from your program..
"We only give homework help to those who show effort"

so, when you post thread again please show the effort...effort can make all of people here to understand the problem. thx
...if u want to insert or update you must to connect vb.net with sql server 2000.
for better (my opinion) u can use module so u can call every time in all form..
this code for connection module :
Imports System.Data
Imports System.Data.SqlClient ' this is very important code that u must added
Module Connect
Public conn As SqlConnection
Public Function GetConnect()
conn = New SqlConnection("Server = YourServerName;" & "initial Catalog = YourDatabaseName;" & " Trusted_Connection=yes")
Return conn
End Function
End Modulethis following code to insert data in database :
Dim check As Integer
Dim conn As SqlConnection
Dim cmdMedical As New SqlCommand
Dim cmdMedical1 As New SqlCommand
Dim daMedical As New SqlDataAdapter
Dim dsMedical As New DataSet
Dim dtMedical As New DataTable
Try
conn = GetConnect() ' this when u call the module to connected....
conn.Open()
cmdMedical = conn.CreateCommand
cmdMedical.CommandText = "SELECT * FROM Medical WHERE Medical_No='" & Trim(txtMedical_No.SelectedItem) & " ' "
daMedical.SelectCommand = cmdMedical
daMedical.Fill(dsMedical, "Medical")
dtMedical = dsMedical.Tables("Medical")
If (dtMedical.Rows.Count > 0) Then
MsgBox("Patient With Medical_No " & Trim(txtMedical_No.Text) & " has been added in data base", MsgBoxStyle.OKOnly, "Message :")
Else
cmdMedical1 = conn.CreateCommand
cmdMedical1.CommandText = "INSERT INTO Medical(IdMedical, Medical_No, BloodType, Disease,BodyAnomaly,Tall,Weight) VALUES('" & Trim(idMedical.Text) & "','" & Trim(txtMedical_No.SelectedItem) & "','" & Trim(cmbBloodType.SelectedItem) & "','" & Trim(txtDisease.Text) & "','" & Trim(txtBodyAnomaly.Text) & "','" & Trim(txtTall.Text) & "','" & Trim(txtWeight.Text) & "')"
check = cmdMedical1.ExecuteReader.RecordsAffected()
If check > 0 Then
MsgBox("Patient With Medical_No " & Trim(txtMedical_No.Text) & " Succesfully Added", MsgBoxStyle.OKOnly, "Message :")
Else
MsgBox("Patient With Medical_No " & Trim(txtMedical_No.Text) & " failed to added", MsgBoxStyle.OKOnly, "Message :")
End If
conn.Close()
End If
Catch ex As Exception
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, " Error Connection!!")
End Tryyou can write the update code by your self and post a new thread if you get the problem..
ok..
all for the best..
NB : don't forget to reply the feedback
Last edited by Jx_Man : Jan 4th, 2008 at 6:15 am.
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Jan 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
for insert code
first
this r import for any connection
At top write this
imports system.data
imports system.data.sqlclient
dim con as new sqlconnection(" "server=NOAHPROJECT;user id=test;password=test;database=test")
con.open()
dim cmd as new Sqlcommand("insert into tablename (name.address)values('"& txtname.text &"','"& txtaddress &" ' ",con)
cmd.excutenonqury()
-----------------------
for update
dim con as new sqlconnection(" "server=NOAHPROJECT;user id=test;password=test;database=test")
con.open()
dim cmd as new Sqlcommand("update tablename set name=' "& txtname &"',address='" & txtadress &"' ",con)
cmd.excutenonqury()
first
this r import for any connection
At top write this
imports system.data
imports system.data.sqlclient
dim con as new sqlconnection(" "server=NOAHPROJECT;user id=test;password=test;database=test")
con.open()
dim cmd as new Sqlcommand("insert into tablename (name.address)values('"& txtname.text &"','"& txtaddress &" ' ",con)
cmd.excutenonqury()
-----------------------
for update
dim con as new sqlconnection(" "server=NOAHPROJECT;user id=test;password=test;database=test")
con.open()
dim cmd as new Sqlcommand("update tablename set name=' "& txtname &"',address='" & txtadress &"' ",con)
cmd.excutenonqury()
•
•
Join Date: Jan 2008
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
for insert code
first
this r import for any connection
At top write this
imports system.data
imports system.data.sqlclient
Then In insert Or add button write this code
dim con as new sqlconnection(" "server=NOAHPROJECT;user id=test;password=test;database=test")
con.open()
dim cmd as new Sqlcommand("insert into tablename (name.address)values('"& txtname.text &"','"& txtaddress &" ' ",con)
cmd.excutenonqury()
-----------------------
for update
In update button
dim con as new sqlconnection(" "server=NOAHPROJECT;user id=test;password=test;database=test")
con.open()
dim cmd as new Sqlcommand("update tablename set name=' "& txtname &"',address='" & txtadress &"' ",con)
cmd.excutenonqury()
first
this r import for any connection
At top write this
imports system.data
imports system.data.sqlclient
Then In insert Or add button write this code
dim con as new sqlconnection(" "server=NOAHPROJECT;user id=test;password=test;database=test")
con.open()
dim cmd as new Sqlcommand("insert into tablename (name.address)values('"& txtname.text &"','"& txtaddress &" ' ",con)
cmd.excutenonqury()
-----------------------
for update
In update button
dim con as new sqlconnection(" "server=NOAHPROJECT;user id=test;password=test;database=test")
con.open()
dim cmd as new Sqlcommand("update tablename set name=' "& txtname &"',address='" & txtadress &"' ",con)
cmd.excutenonqury()
![]() |
•
•
•
•
•
•
•
•
DaniWeb VB.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 2 (0 members and 2 guests)
- Please help with JSP mysql update query (JSP)
- UPDATE query problem (ASP.NET)
- Need update query--Remove the coma "," (PHP)
- retreive and update from check boxes (ColdFusion)
- SQL Delete/Update Error (ColdFusion)
- Beginner: Insert, Update, Delete & Search records from/to sql database (ASP.NET)
- need to update each records after record deleted (PHP)
Other Threads in the VB.NET Forum
- Previous Thread: Advantages of vb.net
- Next Thread: Display table in datagrid



Linear Mode