Imports System.Data
Imports System.Data.OleDb
Public Class DocAdd
Dim con As New OleDb.OleDbConnection
Dim cn As OleDb.OleDbConnection
Dim str As String
Dim cmd As OleDbCommand
Dim da As New OleDbDataAdapter
Dim sql As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
Dim connectionStr As String
connectionStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\My PC\Desktop\MOMS\MOMS\WindowsApplication2\MOMS.accdb"
Dim cn As OleDbConnection = New OleDbConnection(connectionStr)
cn.Open()
sql = "INSERT INTO [Doctor] ([Doctor ID],[Surname],[Title],[Address],[City Town],[State],[Zip],[RegNo],[Phone No],[Mobile No],[Unit Code],[Category])values('" & txtdoctorid.Text & "', '" & txtsurname.Text & "', '" & txttitle.Text & "', '" & txtaddress.Text & "', '" & txtcitytown.Text & "', '" & txtstate.Text & "', '" & txtzip.Text & "', '" & txtregno.Text & "', '" & txtphoneno.Text & "', '" & txtmobileno.Text & "', '" & txtunitcode.Text & "', '" & txtcategory.Text & "')"
'Try
cmd = New OleDbCommand(sql, cn)
cmd.ExecuteNonQuery()
'Catch ex As Exception
'Finally
cn.Close()
'End Try
If txtdoctorid.Text = "" Or txtsurname.Text = "" Or txttitle.Text = "" Or txtaddress.Text = "" Or txtcitytown.Text = "" Or txtstate.Text = "" Or txtzip.Text = "" Or txtregno.Text = "" Or txtphoneno.Text = "" Or txtmobileno.Text = "" Or txtunitcode.Text = "" Or txtcategory.Text = "" = True Then
MessageBox.Show("The registration form is not complete.", "Registration Error", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Else
MessageBox.Show("Register Successful !", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
DocChange.Show()
Me.Hide()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
DocDelete.Show()
Me.Hide()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
DocEnquiry.Show()
Me.Hide()
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Main_Menu.Show()
Me.Hide()
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Application.Exit()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
DocListing.Show()
Me.Hide()
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
End Sub
Class Doc_Add
End Class
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
End Sub
End Class
Searching problem in Vb.net
Page 1 of 17 Replies - 196 Views - Last Post: 07 February 2013 - 03:37 PM
#1
Searching problem in Vb.net
Posted 07 February 2013 - 09:08 AM
I am new to VB.net. I have project in which i have to use any database e.g. Access, SQL. I have to Access to connect with VB.net. I have to register user then search the user and delete it. I am able to Add the user to the data base using the following code, but i tried to search but i was failed because i am totally beginner. I will really appreciate if you guys help me. Thanks.
Replies To: Searching problem in Vb.net
#2
Re: Searching problem in Vb.net
Posted 07 February 2013 - 10:40 AM
I don't see any code for your search. You are needing a Select statement with a Where clause to search for it. Check out W3Schools SQL tutorial.
#3
Re: Searching problem in Vb.net
Posted 07 February 2013 - 01:30 PM
Imports System.Data
Imports System.Data.OleDb
Public Class DocChange
Dim cnnOLEDB As New OleDbConnection
Dim cmdOLEDB As New OleDbCommand
Dim cmdInsert As New OleDbCommand
Dim cmdUpdate As New OleDbCommand
Dim cmdDelete As New OleDbCommand
Dim con As New OleDbConnection
Dim dr As OleDbDataReader
Dim sql As String
Dim sql2 As String
Dim cmd As OleDbCommand
Dim date1 As String
Dim date2 As String
Dim result As Integer
Dim sql3 As String
Dim sql4 As String
Dim cn As OleDb.OleDbConnection
Dim strConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\My PC\Desktop\MOMS\MOMS\WindowsApplication2\MOMS.accdb"""
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DocAdd.Show()
Me.Hide()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Show()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
DocDelete.Show()
Me.Hide()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
DocEnquiry.Show()
Me.Hide()
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Main_Menu.Show()
Me.Hide()
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Application.Exit()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
DocListing.Show()
Me.Hide()
End Sub
Private Sub DocChange_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Dim connectionStr As String
connectionStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\My PC\Desktop\MOMS\MOMS\WindowsApplication2\MOMS.accdb"
sql = "Select * FROM Doctor WHERE DoctorID = @DoctorID"
Dim cn As OleDbConnection = New OleDbConnection(connectionStr)
cn.Open()
cmd = New OleDbCommand(sql, cn)
cmd.Parameters.AddWithValue("DoctorID", txtdocid.Text
)
Dim dr As OleDb.OleDbDataReader = cmd.ExecuteReader
While (dr.Read())
txtdocsur.Text = dr.Item("Surname").ToString
txtdoctitle.Text = dr.Item("Title").ToString
txtdocadd.Text = dr.Item("Address").ToString
txtdoccity.Text = dr.Item("City Town").ToString
txtdocstate.Text = dr.Item("State").ToString
txtdoczip.Text = dr.Item("zip").ToString
txtdocreg.Text = dr.Item("RegNo").ToString
txtdocphone.Text = dr.Item("Phone No").ToString
txtdocmobile.Text = dr.Item("Mobile No").ToString
txtdocunit.Text = dr.Item("Unit Code").ToString
txtdoccat.Text = dr.Item("Category").ToString
End While
cn.Close()
End Sub
Private Sub txtsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
End Sub
End Class
This is the code i am using to get the data from the database, i dont know how to update it. Please help me. Thank you
#4
Re: Searching problem in Vb.net
Posted 07 February 2013 - 02:13 PM
Is there an error?
#5
Re: Searching problem in Vb.net
Posted 07 February 2013 - 02:25 PM
no iam not getting an error. i just want to know how to update code. i dont know the code. i have search the internet but didnt get any information that i can understand.
#6
Re: Searching problem in Vb.net
Posted 07 February 2013 - 02:49 PM
I don't know what the question is here. Update what code? Does the code not get the results you want? Are you sure the connection string is correct?
#7
Re: Searching problem in Vb.net
Posted 07 February 2013 - 02:58 PM
So you're basically asking us to teach you vb.net in this 1 thread... the issue in this (updating some simple code) is outside of the scope of this thread. I highly recommend going to youtube and going through some tutorials.
#8
Re: Searching problem in Vb.net
Posted 07 February 2013 - 03:37 PM
If you have any errors you should post these as well. But your Doctor ID field has a space:
I never have spaces in field names
sql = "Select * FROM Doctor WHERE DoctorID = @DoctorID" 'should be sql = "Select * FROM Doctor WHERE [Doctor ID] = @DoctorID"
I never have spaces in field names
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|