Question

Need help!!! I need two programs that use one common database.. One program using a Visual...

Need help!!! I need two programs that use one common database.. One program using a Visual Basic windows form using textboxes for data input (first name, last name, phone, email) and it should save the info into an SQL database when a save button is clicked. Second program using a C# windows form that has a drop down menu with all the names that have been saved into the database, when one name is clicked all their information should pop up in a message box.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

For Database, SQL Server Database has been used

1. Open sql server management studio, Select Master database , Open a new query window
2. First A database has been created by command
USE TestDB
3. Create the table by given field name

USE TestDB
CREATE TABLE Student
(
     
   first_name varchar (50) NULL,
   last_name varchar (50) NULL,
   phone varchar (50) NULL,
   email varchar (50) NULL
)

  

4. Then using Visual basic win form a project (DBAdd) created

New Project ► Recent Sort by: Default Search (Ctrl+E) Installed Type: Visual Basic A project for creating an application wit

Form1.vb Form1.vb [Design] + X - Form1 o x First Name Last Name Phone Email Submit

Name of each text Field is changed by property window

First Name : txtfname

Last name : txtlname

Phone :txtphone

Mail id : txtmail

Name of Button : btnSubmit

CODE

Imports System.Data
Imports System.Data.SqlClient
Public Class Form1

'' Button Add Code
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click

'' Exception handeling , if any Exception Occurs
Try
''Connection string for sql server
'' Server= SQL serve Instance Name
'' Database = Data base Name
'' User Id= Sql server User id
'' Password = SQL server login password

Dim connectionString As String = "Server=AKSHAYA\SQL12;Database=TestDB;User Id=sa;Password=Sa1234#"

Using cn As New SqlConnection(connectionString)
cn.Open()
Dim cmd As New SqlCommand()
''INSERT COMMAND WITH PARAMETER
cmd.CommandText = "INSERT INTO Student(first_name, last_name, phone, email) VALUES(@first_name, @last_name, @phone, @email)"

'' DEFINE PARAMETER FOR first_name
Dim param1 As New SqlParameter()
param1.ParameterName = "@first_name"
param1.Value = txtfname.Text.Trim() '' get Data from Field , Trim eliminates extra space
cmd.Parameters.Add(param1)

'' DEFINE PARAMETER FOR last_name
Dim param2 As New SqlParameter()
param2.ParameterName = "@last_name"
param2.Value = txtlname.Text.Trim() '' get Data from Field
cmd.Parameters.Add(param2)

'' DEFINE PARAMETER FOR phone
Dim param3 As New SqlParameter()
param3.ParameterName = "@phone"
param3.Value = txtphone.Text.Trim() '' get Data from Field
cmd.Parameters.Add(param3)

'' DEFINE PARAMETER FOR email
Dim param4 As New SqlParameter()
param4.ParameterName = "@email"
param4.Value = txtmail.Text.Trim() '' get Data from Field
cmd.Parameters.Add(param4)


cmd.Connection = cn '' Specify Connection object
cmd.ExecuteNonQuery() ''Execute the insertion query
cn.Close()
'' show success message
MessageBox.Show("Data insert success")
End Using

Catch ex As Exception '' when Exception occurs
MessageBox.Show(ex.Message.ToString)
End Try
End Sub
End Class

SCREEN SHOT CODE

Imports System.Data Imports System.Data.SqlClient 1 reference Public Class Form1 Button Add Code O references Private Sub bDEFINE PARAMETER FOR last_name Dim param2 As New SqlParameter() param2. ParameterName = @last_name param2.Value = txtlname.


5. To fetch data from table using C# winform a project (DBGet) created

New Project ? x Recent Sort by: Default Search (Ctrl+E) Installed 03 Visual C# Get Started Windows Universal Windows Desktop

The form is designed

Form1.cs Form1.cs (Design) + X Form1 Dox Name

The combobox id change to cmbName

CODE

using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace DBGet
{
public partial class Form1 : Form
{
//Specifying connection path to Database
string connectionString = "Server=AKSHAYA\\SQL12;Database=TestDB;User Id=sa;Password=Sa1234#";
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
try//Handels any Exception
{
// Select Query for table Student
string Sql = "select ( first_name+ ' ' + last_name) Name, phone, email from Student";
// first_name and last_name concatenated to a single field as "Name"

//Using the connection string create Connection instance
using (SqlConnection con = new SqlConnection(connectionString))
{
//Create a Data Adatapter to fetch data from table
using (SqlDataAdapter sda = new SqlDataAdapter(Sql, con))
{
//Fill the DataTable with records from Table.
DataTable dt = new DataTable();
sda.Fill(dt);

//Insert the Default Item to DataTable.
DataRow row = dt.NewRow();
row[1] = 0;
row[0] = "Please select";
dt.Rows.InsertAt(row, 0);

//Assign DataTable as DataSource.
//cmbName is id Combox on Form Design

cmbName.DisplayMember = "Name";
cmbName.ValueMember = "phone";
//Phone No as unique field, it more significant for searching, so binded as value field
cmbName.DataSource = dt;


}
}
}
catch
{ }
}
//Method invoked when selection changed of combobox "cmbName"
private void cmbName_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
//Select query by getting value propery from comboBox cmbName
string Sql = "select first_name,last_name, phone, email from Student where phone ='" + cmbName.SelectedValue +"'" ;

using (SqlConnection con = new SqlConnection(connectionString))
{
using (SqlDataAdapter sda = new SqlDataAdapter(Sql, con))
{
//Fill the DataTable with records from Table.
DataTable dt = new DataTable();
sda.Fill(dt);

//Display Data concatenated to a message string variable
string msg = "First Name="+ dt.Rows[0]["first_name"] + "\nLast Name=" + dt.Rows[0]["last_name"] +
"\nPhone=" + dt.Rows[0]["phone"] + "\nMail = " + dt.Rows[0]["email"] ;

//Display the variable
MessageBox.Show(msg);

}
}

}
catch
{   
}
} // end of selection event
} // end of Form1 class
}

SCREENSHOT CODE

using System; using System.Data; using System.Windows.Forms; using System.Data.SqlClient; namespace DBGet 3 references public

//Fill the DataTable with records from Table. DataTable dt = new DataTable(); sda.Fill(dt); //Insert the Default Item to Data

1/Select query by getting value propery from comboBox cmbName string Sql = select first_name, last_name, phone, email from S

OUT PUT

1. INSERTION

. Form1 - 0 x First Name Rohit Last Name Sam Phone 891234563 Email rh@gmail.com Submit Data insert success ок |

2. VIEW FORM

Form1 Name Rohit Sam First Name=Rohit Last Name=Sam Phone=891234563 Mail = rh@gmail.com OK

Add a comment
Know the answer?
Add Answer to:
Need help!!! I need two programs that use one common database.. One program using a Visual...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • ***PLEASE AVOID USING A "CLASS" IN SOLUTION*** thank you. Please use Visual Studio to write a...

    ***PLEASE AVOID USING A "CLASS" IN SOLUTION*** thank you. Please use Visual Studio to write a C# program to allow user to store contact information. 1. User should be able to type in name, E-mail and phone number in the text boxes and click Add button to save the contact record. Every time when user add record, user should be able to see all the information displayed in the right side display text box. (allow up to 10 records) 2....

  • I need help creating a program in Visual Basic, (I'm using Visual Studio 2013), that will...

    I need help creating a program in Visual Basic, (I'm using Visual Studio 2013), that will start with a screen welcoming people to a student database management system. It will then ask them to click next to take them to another screen that will have 5 tabs. Student enquiry, Registration, courses, faculty, and fee payments. Depending on what is clicked will take them to that screen and have information related to that on that screen. It doesnt have to be...

  • Visual Basic - I need to make a program to search a text file that is...

    Visual Basic - I need to make a program to search a text file that is in the debug. Found from "IO.File.ReadAllLines".  When the word is typed into a textbox and button pressed, the program should show which line the word first appeared in the text through a message box or another feature. If it is not found, the program will open a message box. I don't have the full code, please assist

  • Write a contacts database program that presents the user with a menu that allows the user...

    Write a contacts database program that presents the user with a menu that allows the user to select between the following options: (In Java) Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...

  • How do you do this using visual studio on a Mac? You are tasked with creating...

    How do you do this using visual studio on a Mac? You are tasked with creating an application with five PictureBox controls. In the Poker Large folder, you will find JPEG image files for a complete deck of poker cards. Feel free to choose any card image that you like or be creative with this application. Each PictureBox should display a different card from the set of images. When the user clicks any of the PictureBox controls, the name of...

  • C++ and Using Microsoft Visual Studio. Write 2 programs: One program will use a structure to...

    C++ and Using Microsoft Visual Studio. Write 2 programs: One program will use a structure to store the following data on a company division: Division Name (East, West, North, and South) Quarter (1, 2, 3, or 4) Quarterly Sales The user should be asked for the four quarters' sales figures for the East, West, North, and South divisions. The data for each quarter for each division should be written to a file. The second program will read the data written...

  • This is Visual Basic program, thank you for your help In this assignment, you'll start a...

    This is Visual Basic program, thank you for your help In this assignment, you'll start a new Windows Forms application. Assume we have the data shown below: Names_first={"jack","marjy","tom","luke","sam","al","joe","miky","lu"} Name_last={"jones","ety","fan","spence","amin",sid","bud","ant","ben"} Amounts={234.45,8293.1,943.25,27381.0,271.39,7436.12,2743.0,1639.95,2354.2} The above will allows us to emulate reading data from a file, which we will learn in the next unit. For now, we will assume the data above has been read from a file. We need to process this data in fast way. For that purpose, we need to: Declare...

  • The following form will be used to determine the sales commission of employees. Using Visual Basic...

    The following form will be used to determine the sales commission of employees. Using Visual Basic Studio, build the form with these features:  The checkbox “Target Met” must be disabled.  The title of the form should appear as “Sales Commissions” Write the code to do the following: After entering the totals sales, the checkbox will automatically be checked if the average sales per month was $1,500 or more. Note: The average sales per month can be calculated by...

  • Using C#: Create a Form that consists of 3 radio buttons, two textboxes, a label and...

    Using C#: Create a Form that consists of 3 radio buttons, two textboxes, a label and a button. The three radio buttons should represent the names of three fonts, e.g. “Arial”, “Calibri” and “Times New Roman”. In the one textbox, a user should type a message and in the other textbox, the user should type a size. When the user clicks the button, the label should be updated with the text the user typed in the one textbox, using the...

  • I have to use java programs using netbeans. this course is introduction to java programming so...

    I have to use java programs using netbeans. this course is introduction to java programming so i have to write it in a simple way using till chapter 6 (arrays) you can use (loops , methods , arrays) You will implement a menu-based system for Hangman Game. Hangman is a popular game that allows one player to choose a word and another player to guess it one letter at a time. Implement your system to perform the following tasks: Design...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT