Dot Net Framework
A)
Write a program in C# .Net to create a function for the sum of two numbers.
Answer :
namespace WinFormsApp18
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static int Sum(int a, int b)
{
return a + b;
}
private void button1_Click(object sender, EventArgs e){
int a = Convert .ToInt32 (textBox1.Text);
int b = Convert .ToInt32 (textBox2.Text);
int c = Sum (a, b);
label5.Text = c.ToString();
}
}
}
Output :
B)
Write a VB.NET program to create teacher table (Tid, TName, subject) Insert the
records (Max: 5). Search record of a teacher
whose name is “Seeta” and display result.
Answer :
Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=C:\Users\Saurabh\Desktop\New folder\teacher.accdb")
Dim adpt As New OleDbDataAdapter("Select
* from teacher", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "teacher")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "teacher"
Return ds
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
display()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = "insert into teacher values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & TextBox3.Text & "')"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
Private Sub TextBox4_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox4.KeyDown
ds.Clear()
Dim adp As New OleDbDataAdapter("select
* from teacher Where Name like '%"
& TextBox4.Text & "%'", con)
adp.Fill(ds, "search")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "search"
End Sub
End Class
Output :
No comments:
Post a Comment