Imports System.Data.SqlClient Public Class Goods_details Public con As New SqlConnection("server=.\sqlexpress;Integrated security=true;database=cargo;") Dim cmd As New SqlCommand() Dim iid As String Dim dt As New DataTable Dim ds As New DataSet() Dim dt1 As New DataTable() Dim da As New SqlDataAdapter Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Try con.Open() Dim da As New SqlDataAdapter("select aid,gtypes from ship where Dno='" & ComboBox1.Text & "' ", con) Dim ds As New DataSet Dim dt As New DataTable Dim dr As DataRow da.Fill(ds) da.Fill(dt) con.Close() For Each dr In dt.Rows TextBox2.Text = dr.Item(0) TextBox3.Text = dr.Item(1) Next Catch ex As Exception End Try End Sub Private Sub Goods_details_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ship() data() ident1() End Sub Public Sub ship() Try con.Open() Dim da As New SqlDataAdapter("select Dno from ship", con) Dim dt As New DataTable Dim dr As DataRow da.Fill(dt) con.Close() For Each dr In dt.Rows ComboBox1.Items.Add(dr.Item(0)) Next Catch ex As Exception End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click con.Open() cmd = New SqlCommand("insert into goodsdetails values('" & ComboBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')", con) cmd.ExecuteNonQuery() MsgBox("Saved Successfully") con.Close() Data() refreshform() ident1() End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Dim shipno As String = "" shipno = InputBox("Enter Delivery No Number") If shipno = "" Then Exit Sub Dim sqlstr As String con.Open() Dim cmd As New SqlCommand cmd.Connection = con sqlstr = "Select * from goodsdetails Where Acid='" & shipno & "'" cmd.CommandText = sqlstr Dim r As SqlDataReader = cmd.ExecuteReader If r.Read Then TextBox1.Text = r(0) ComboBox1.Text = r(1) TextBox2.Text = r(2) TextBox3.Text = r(3) TextBox4.Text = r(4) Else MsgBox("Acid Number not found", MsgBoxStyle.Information) End If r.Close() r = Nothing cmd.Dispose() cmd = Nothing con.Close() End Sub Public Sub data() Try con.Open() Dim da As New SqlDataAdapter("select * from goodsdetails", con) Dim ds As New DataSet da.Fill(ds) DataGridView1.DataSource = ds.Tables(0) con.Close() Catch ex As Exception End Try End Sub Private Sub refreshform() TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" ComboBox1.Text = "" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try con.Open() Dim cmd As New SqlCommand cmd.CommandText = "update goodsdetails set aid=' " & TextBox2.Text & " ',gdsname='" & TextBox3.Text & "',tot='" & TextBox4.Text & "' where Acid=" & TextBox1.Text & " " cmd.Connection = con cmd.ExecuteNonQuery() MsgBox("Updated SucussFully") con.Close() data() Catch ex As Exception End Try refreshform() ident1() data() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Try con.Open() Dim cmd As New SqlCommand("delete from goodsdetails where Acid=" & TextBox1.Text & " ", con) cmd.ExecuteNonQuery() MsgBox("Deleted SucussFully") con.Close() Catch ex As Exception End Try data() refreshform() ident1() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click refreshform() End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Me.Close() End Sub Public Sub ident1() dt.Rows.Clear() dt.Columns.Clear() dt1.Rows.Clear() dt1.Columns.Clear() da = New SqlDataAdapter("select * from goodsdetails", con) da.Fill(dt) da = New SqlDataAdapter("select ident_current('goodsdetails')", con) da.Fill(dt1) Dim id As Integer If dt.Rows.Count = 0 Then id = 0 Else id = Integer.Parse(dt1.Rows(0)(0).ToString()) End If id = id + 1 TextBox1.Text = id.ToString() End Sub End ClassImports System.Data.SqlClient Public Class payment Public con As New SqlConnection("server=.\sqlexpress;Integrated security=true;database=cargo;") Dim cmd As New SqlCommand() Dim iid As String Dim dt As New DataTable Dim ds As New DataSet() Dim dt1 As New DataTable() Dim da As New SqlDataAdapter Private Sub payment_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try con.Open() Dim da As New SqlDataAdapter("select Dno from goodsdetails", con) Dim dt As New DataTable Dim dr As DataRow da.Fill(dt) con.Close() For Each dr In dt.Rows ComboBox1.Items.Add(dr.Item(0)) Next Catch ex As Exception End Try ident1() End Sub Public Sub ident1() dt.Rows.Clear() dt.Columns.Clear() dt1.Rows.Clear() dt1.Columns.Clear() da = New SqlDataAdapter("select * from pay", con) da.Fill(dt) da = New SqlDataAdapter("select ident_current('pay')", con) da.Fill(dt1) Dim id As Integer If dt.Rows.Count = 0 Then id = 0 Else id = Integer.Parse(dt1.Rows(0)(0).ToString()) End If id = id + 1 TextBox5.Text = id.ToString() End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged Try con.Open() Dim da As New SqlDataAdapter("select aid,gdsname,tot from goodsdetails where Dno='" & ComboBox1.Text & "' ", con) Dim ds As New DataSet Dim dt As New DataTable Dim dr As DataRow da.Fill(ds) da.Fill(dt) con.Close() For Each dr In dt.Rows TextBox1.Text = dr.Item(0) TextBox2.Text = dr.Item(1) TextBox3.Text = dr.Item(2) Next Catch ex As Exception End Try End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If (Val(TextBox3.Text) > 0 And Val(TextBox3.Text) >= Val(TextBox4.Text)) Then con.Open() cmd = New SqlCommand("insert into pay values('" & ComboBox1.Text & "','" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')", con) cmd.ExecuteNonQuery() MsgBox("Patment Paid") con.Close() If con.State = ConnectionState.Closed Then con.Open() Dim cmd1 As New SqlCommand("select * from goodsdetails where Dno='" & ComboBox1.Text & "'", con) Dim cmd2 As New SqlCommand Dim dr As SqlDataReader dr = cmd1.ExecuteReader cmd2.Connection = con If dr.Read Then dr.Close() cmd2.CommandText = "update goodsdetails set tot=tot-" & TextBox4.Text & " where Dno='" & ComboBox1.Text & "' " cmd2.ExecuteNonQuery() MsgBox("Amount Reduced") End If ident1() Else MessageBox.Show("Balance inconvenience") End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) email.Show() End Sub End ClassImports System.Data.SqlClient Public Class employee Public con As New SqlConnection("server=.\sqlexpress;Integrated security=true;database=cargo;") Dim cmd As New SqlCommand() Private Sub employee_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load data() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If con.State = ConnectionState.Closed Then con.Open() cmd = New SqlCommand("insert into emp values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "','" & TextBox7.Text & "')", con) cmd.ExecuteNonQuery() MsgBox("Saved Successfully") con.Close() Data() refreshform() End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Dim eid As String = "" eid = InputBox("Enter Employee ID") If eid = "" Then Exit Sub Dim sqlstr As String If con.State = ConnectionState.Closed Then con.Open() Dim cmd As New SqlCommand cmd.Connection = con sqlstr = "Select * from emp Where eid='" & eid & "'" cmd.CommandText = sqlstr Dim r As SqlDataReader = cmd.ExecuteReader If r.Read Then TextBox1.Text = r(0) TextBox2.Text = r(1) TextBox3.Text = r(2) TextBox4.Text = r(3) TextBox5.Text = r(4) TextBox6.Text = r(5) TextBox7.Text = r(6) Else MsgBox("Employee not found", MsgBoxStyle.Information) End If r.Close() r = Nothing cmd.Dispose() cmd = Nothing con.Close() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Try If con.State = ConnectionState.Closed Then con.Open() Dim cmd As New SqlCommand cmd.CommandText = "update emp set ename=' " & TextBox2.Text & " ',addr='" & TextBox3.Text & "',pno='" & TextBox4.Text & "',desi='" & TextBox5.Text & "',sal='" & TextBox6.Text & "',doj='" & TextBox7.Text & "' where eid='" & TextBox1.Text & " ' " cmd.Connection = con cmd.ExecuteNonQuery() MsgBox("Updated SucussFully") con.Close() Data() Catch ex As Exception End Try refreshform() Data() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'Try If con.State = ConnectionState.Closed Then con.Open() Dim cmd As New SqlCommand("delete from emp where eid='" & TextBox1.Text & "' ", con) cmd.ExecuteNonQuery() MsgBox("Deleted SucussFully") con.Close() ' Catch ex As Exception 'End Try data() refreshform() End Sub Private Sub refreshform() TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox6.Text = "" TextBox7.Text = "" End Sub
Write, Run & Share VB.net code online using OneCompiler's VB.net online compiler for free. It's one of the robust, feature-rich online compilers for VB.net language, running on the latest version 16. Getting started with the OneCompiler's VB.net compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as VB.net
. OneCompiler also has reference programs, where you can look for the sample code to get started with.
OneCompiler's VB.net online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample VB.net program which takes name as input and prints hello message with your name.
Public Module Program
Public Sub Main(args() As string)
Dim name as String = Console.ReadLine() ' Reading input from STDIN
Console.WriteLine("Hello " & name) ' Writing output to STDOUT
End Sub
End Module
Visual Basic is a event driven programming language by Microsoft, first released in the year 1991.
Variable is a name given to the storage area in order to identify them in our programs.
Simple syntax of Variable declaration is as follows
Dim variableName [ As [ New ] dataType ] [ = initializer ]
variableName = value
If condition-expression Then
'code
End If
If(conditional-expression)Then
'code if the conditional-expression is true
Else
'code if the conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
Else If(conditional-expression) Then
'code if the above conditional-expression is true
Else
'code if the above conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
If(conditional-expression)Then
'code if the above conditional-expression is true
End If
End If
Select [ Case ] expression
[ Case expressionlist
'code ]
[ Case Else
'code ]
End Select
For counter [ As datatype ] = begin To end [ Step step ]
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ counter ]
For Each element [ As datatype ] In group
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ element ]
While conditional-expression
'Code
[ Continue While ]
'Code
[ Exit While ]
'Code
End While
Do { While | Until } conditional-expression
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop
Do
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop { While | Until } conditional-expression
Procedure is a sub-routine which contains set of statements. Usually Procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
Procedures are of two types.
Functions return a value when they are called.
[accessModifiers] Function functionName [(parameterList)] As returnType
'code
End Function
Sub-procedures are similar to functions but they don't return any value.
Sub ProcedureName (parameterList)
'Code
End Sub