Dot Net Framework
A)
Write a C#.Net application to display the vowels from a given String.
Answer :
namespace WinFormsApp21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
String str = (textBox1.Text);
char[] chars = str.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
switch (chars[i])
{
case 'A' or 'a':
listBox1.Items.Add(chars[i].ToString());
break;
case 'E' or 'e':
listBox1.Items.Add(chars[i].ToString());
break;
case 'I' or 'i':
listBox1.Items.Add(chars[i].ToString());
break;
case 'O' or 'o':
listBox1.Items.Add(chars[i].ToString());
break;
case 'U' or 'u':
listBox1.Items.Add(chars[i].ToString());
break;
}
}
}
}
}
Output :
B)
Write a VB.NET program to accept the details of product (PID, PName,
expiry_date,
price). Store it into the database and display it on data grid view.
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\product.accdb")
Dim adpt As New OleDbDataAdapter("Select
* from product", con)
Dim cmd As New OleDbCommand
Dim ds As New DataSet
Public Function display()
adpt.Fill(ds, "product")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "product"
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 product values(" & TextBox1.Text & ",'" & TextBox2.Text & "','" & DateTimePicker1.Value & "'," &
TextBox4.Text & ")"
con.Open()
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Inserted Successfully...!")
End If
con.Close()
ds.Clear()
display()
End Sub
End Class
Output :
No comments:
Post a Comment