0% found this document useful (0 votes)
45 views

Data Source SAI/SQLEXPRESS Initial Catalog Cancer Integrated Security True

This document contains code for an image comparison application that connects to a SQL database. It includes: 1. Methods to load and display images from the database in two picture boxes. 2. Methods to retrieve data from different tables in the database based on an ID and populate textboxes. 3. Event handlers for buttons to insert, update, delete and search records in the medicine table.

Uploaded by

Helloproject
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Data Source SAI/SQLEXPRESS Initial Catalog Cancer Integrated Security True

This document contains code for an image comparison application that connects to a SQL database. It includes: 1. Methods to load and display images from the database in two picture boxes. 2. Methods to retrieve data from different tables in the database based on an ID and populate textboxes. 3. Event handlers for buttons to insert, update, delete and search records in the medicine table.

Uploaded by

Helloproject
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Imports System.Data.

SqlClient
Imports System.IO
Public Class imagecompare
Dim con As New SqlConnection("Data Source=SAI\SQLEXPRESS;Initial
Catalog=cancer;Integrated Security=True")
Dim com As New SqlCommand
Dim adp As New SqlDataAdapter
Dim ds As DataSet
Dim qry As String
Dim i As Integer
Dim j As Integer
Dim fn As String
Dim p As String

Private Sub DrawToScale(ByVal img As Image)


PictureBox1.Image = New Bitmap(img)
'PictureBox2.Image = New Bitmap(img)
End Sub

Private Sub DrawToScale1(ByVal img As Image)


PictureBox2.Image = New Bitmap(img)
'PictureBox2.Image = New Bitmap(img)
End Sub
Private Sub imagecompare_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Form4.Close()
Try

Dim sql As String = "select cimage from cancer1 where imgloc='" +


TextBox5.Text + "'"

con.Open()

Dim cmd As SqlCommand = New SqlCommand(sql, con)


Dim b() As Byte
b = cmd.ExecuteScalar()

If (b.Length > 0) Then


Dim stream As New MemoryStream(b, True)
stream.Write(b, 0, b.Length)
'Display image
DrawToScale(New Bitmap(stream))
stream.Close()
End If

con.Close()

Catch ex As Exception

Form7.Show()
'Me.Hide()
'MsgBox(" Invalid Register No Select Correct Register Number")
End Try

Try

Dim sql1 As String = "select pimage from cancer1 where imgloc='"


+ TextBox5.Text + "'"

con.Open()

Dim cmd1 As SqlCommand = New SqlCommand(sql1, con)


Dim b1() As Byte
b1 = cmd1.ExecuteScalar()

If (b1.Length > 0) Then


Dim stream1 As New MemoryStream(b1, True)
stream1.Write(b1, 0, b1.Length)
'Display image
DrawToScale1(New Bitmap(stream1))
stream1.Close()
End If

con.Close()

Catch ex As Exception

Form7.Show()
'Me.Hide()
'MsgBox(" Invalid Register No Select Correct Register Number")
End Try

Try
qry = "select cid,cname,cdesc,pname from cancer1 where imgloc='"
+ TextBox5.Text + "'"
com = New SqlCommand(qry, con)
adp = New SqlDataAdapter(com)
ds = New DataSet
adp.Fill(ds, "cancer1")

TextBox1.Text = ds.Tables("cancer1").Rows(0)(0)
TextBox2.Text = ds.Tables("cancer1").Rows(0)(1)
TextBox3.Text = ds.Tables("cancer1").Rows(0)(2)
TextBox4.Text = ds.Tables("cancer1").Rows(0)(3)

'Txt_nation.Text = ds.Tables("newuserl").Rows(0)(10)
'Txt_DOJ.Text = ds.Tables("newuser").Rows(0)(11)
Catch ex As Exception

End Try

Try
qry = "select * from food where cid='" + TextBox1.Text + "'"
com = New SqlCommand(qry, con)
adp = New SqlDataAdapter(com)
ds = New DataSet
adp.Fill(ds, "food")

TextBox6.Text = ds.Tables("food").Rows(0)(3)

'Txt_nation.Text = ds.Tables("newuserl").Rows(0)(10)
'Txt_DOJ.Text = ds.Tables("newuser").Rows(0)(11)

Catch ex As Exception

End Try

Try
qry = "select * from medicine where cid='" + TextBox1.Text + "'"
com = New SqlCommand(qry, con)
adp = New SqlDataAdapter(com)
ds = New DataSet
adp.Fill(ds, "medicine")

TextBox7.Text = ds.Tables("medicine").Rows(0)(0)
TextBox8.Text = ds.Tables("medicine").Rows(0)(4)
TextBox9.Text = ds.Tables("medicine").Rows(0)(1)
TextBox10.Text = ds.Tables("medicine").Rows(0)(5)

'Txt_nation.Text = ds.Tables("newuserl").Rows(0)(10)
'Txt_DOJ.Text = ds.Tables("newuser").Rows(0)(11)

Catch ex As Exception

End Try

Try
qry = "select * medicine where mid='" + TextBox7.Text + "'"
com = New SqlCommand(qry, con)
adp = New SqlDataAdapter(com)
ds = New DataSet
adp.Fill(ds, "medicine")

'TextBox7.Text = ds.Tables("medicine").Rows(0)(0)
TextBox8.Text = ds.Tables("medicine").Rows(0)(4)
TextBox9.Text = ds.Tables("medicine").Rows(0)(1)
TextBox10.Text = ds.Tables("medicine").Rows(0)(5)

'Txt_nation.Text = ds.Tables("newuserl").Rows(0)(10)
'Txt_DOJ.Text = ds.Tables("newuser").Rows(0)(11)
Catch ex As Exception

End Try

End Sub

End Class

Dim con As New SqlConnection("Data Source=SAI\SQLEXPRESS;Initial


Catalog=cancer;Persist Security Info=True;User ID=sa;Password=sql")
Dim com, cmd As New SqlCommand
Dim adp As New SqlDataAdapter
Dim ds As DataSet
Dim qry, str As String
Dim i As Integer
Dim j As Integer
Dim fn As String
Dim p As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or
TextBox4.Text = "" Or TextBox5.Text = "" Then
MsgBox("enter all data")
Else
con.Open()
str = "insert into medicine values( '" & TextBox1.Text & "','" &
TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" &
TextBox5.Text & "','" & TextBox6.Text & "')"
cmd = New SqlCommand(str, con)
cmd.ExecuteNonQuery()
MsgBox("successfully saved")
'usrmenu.Show()
Me.Hide()
End If

TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Try
Dim s As String
s = InputBox("Enter Medicine id:")
str = "select * from medicine where mid='" + s + "'"
cmd = New SqlCommand(str, con)
adp = New SqlDataAdapter(cmd)
ds = New DataSet
adp.Fill(ds, "medicine")
TextBox1.Text = ds.Tables("medicine").Rows(0)(0)
TextBox2.Text = ds.Tables("medicine").Rows(0)(1)
TextBox3.Text = ds.Tables("medicine").Rows(0)(2)
TextBox4.Text = ds.Tables("medicine").Rows(0)(3)
TextBox5.Text = ds.Tables("medicine").Rows(0)(4)
TextBox6.Text = ds.Tables("medicine").Rows(0)(5)

Catch ex As Exception

MsgBox(ex.Message)
End Try
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
con.Open()
str = "update medicine set mid='" & TextBox1.Text & "', mname='" &
TextBox2.Text & "',cid='" & TextBox3.Text & "',ctype='" & TextBox4.Text &
"',edate='" & TextBox5.Text & "',dur='" & TextBox6.Text & "' where mid='" +
TextBox1.Text + "' "
cmd = New SqlCommand(str, con)
cmd.ExecuteNonQuery()
MsgBox("data updated")
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox1.Text = ""
TextBox6.Text = ""
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
con.Open()
str = "delete from medicine where mid='" + TextBox1.Text + "' "
cmd = New SqlCommand(str, con)
cmd.ExecuteNonQuery()
MsgBox("data deleted")
TextBox2.Text = ""
TextBox6.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox1.Text = ""
End Sub

Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
TextBox3.Items.Clear()
qry = "select cid from cancer1"
com = New SqlCommand(qry, con)
adp = New SqlDataAdapter(com)
ds = New DataSet
adp.Fill(ds, "cancer1")
i = ds.Tables("cancer1").Rows.Count
Dim j As Integer
For j = 0 To i - 1
TextBox3.Items.Add(ds.Tables("cancer1").Rows(j)(0))
Next

Try
Dim p As String
str = "select mid from medicine"
com = New SqlCommand(str, con)
adp = New SqlDataAdapter(com)
ds = New DataSet
adp.Fill(ds, "medicine")
i = ds.Tables("medicine").Rows.Count
p = ds.Tables("medicine").Rows(i - 1)(0)
p = Mid(p, 4)
p = Val(p) + 1
'If Len(p) = 1 Then
' p = "000" + p
'ElseIf Len(p) = 2 Then
' p = "00" + p
'ElseIf Len(p) = 3 Then
' p = "0" + p
'End If
TextBox1.Text = "MED" + p

Catch ex As Exception
TextBox1.Text = "MED1"
End Try
End Sub

Private Sub TextBox3_SelectedIndexChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles TextBox3.SelectedIndexChanged
qry = "select cname from cancer1 where cid='" + TextBox3.SelectedItem
+ "'"
com = New SqlCommand(qry, con)
adp = New SqlDataAdapter(com)
ds = New DataSet
adp.Fill(ds, "cancer1")
TextBox4.Text = ds.Tables("cancer1").Rows(0)(0)
End Sub

You might also like