This code will Insert,Delete,Update the data into faculty table.
using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace InsertUpdateDeleteDemo
{
public partial class frmMain : Form
{
SqlConnection con= new SqlConnection("Data Source=.;Initial
Catalog=Sample;Integrated Security=true;");
SqlCommand cmd;
SqlDataAdapter adapt;
//ID variable used in Updating and Deleting Record
int ID = 0;
public frmMain()
{
InitializeComponent();
DisplayData();
}
//Insert Data
private void btn_Insert_Click(object sender, EventArgs e)
{
if (txt_Fid.Text != "" && txt_Name.Text !=
""&&txt_Office.Text != "")
{
cmd = new SqlCommand("insert into Faculty(Fid,Name,Office)
values(@Fid,@name,@Office)", con);
con.Open();
cmd.Parameters.AddWithValue("@FID", txt_Fid.Text);
cmd.Parameters.AddWithValue("@Name", txt_Name.Text);
cmd.Parameters.AddWithValue("@Office", txt_Office.Text);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record Inserted Successfully");
DisplayData();
ClearData();
}
else
{
MessageBox.Show("Please Provide Details!");
}
}
//Display Data in DataGridView
private void DisplayData()
{
con.Open();
DataTable dt=new DataTable();
adapt=new SqlDataAdapter("select * from Faculty",con);
adapt.Fill(dt);
dataGridView1.DataSource = dt;
con.Close();
}
//Clear Data
private void ClearData()
{
txt_Name.Text = "";
txt_State.Text = "";
ID = 0;
}
//dataGridView1 RowHeaderMouseClick Event
private void dataGridView1_RowHeaderMouseClick(object sender,
DataGridViewCellMouseEventArgs e)
{
ID =
Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
txt_Fid.Text =
dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
txt_Name.Text =
dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
txt_Office.Text =
dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
}
//Update Record
private void btn_Update_Click(object sender, EventArgs e)
{
if (txt_Fid.Text != "" && txt_Name.Text != "" &&
txt_Name.Office != "")
{
cmd = new SqlCommand("update Faculty set Fid=@FID,
Name=@Name,Office=@Office where ID=@id", con);
con.Open();
cmd.Parameters.AddWithValue("@id", ID);
cmd.Parameters.AddWithValue("@Fid", txt_Fid.Text);
cmd.Parameters.AddWithValue("@Name", txt_Name.Text);
cmd.Parameters.AddWithValue("@Office", txt_Office.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Record Updated Successfully");
con.Close();
DisplayData();
ClearData();
}
else
{
MessageBox.Show("Please Select Record to Update");
}
}
//Delete Record
private void btn_Delete_Click(object sender, EventArgs e)
{
if(ID!=0)
{
cmd = new SqlCommand("delete Faculty where ID=@id",con);
con.Open();
cmd.Parameters.AddWithValue("@id",ID);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record Deleted Successfully!");
DisplayData();
ClearData();
}
else
{
MessageBox.Show("Please Select Record to Delete");
}
}
}
}
1. C# Code (40) You have three textboxes. You have a table: Faculty (FID, Name, Office) Assuming you have Access DatasSourcel objeet, which linked to the Table Faculty. (1) Write the code for a...
1. C# Code (40) You have three textboxes. You have a table: Faculty (FID, Name, Office) Assuming you have Access DatasSourcel objeet, which linked to the Table Faculty. (1) Write the code for a "Insert" button that will insert a record into the above table (2) Write the code for a "Delete" button. 1. C# Code (40) You have three textboxes. You have a table: Faculty (FID, Name, Office) Assuming you have Access DatasSourcel objeet, which linked to the Table...
#1. Single linked list - find... Extra info/hint? It's free For this problem, I have a complete linked list program which supports the following commands from the user: insert, display, delete, average, find, insertBefore, insertAfter. insert allows them to insert a number into the current list, display will display the numbers in the current list etc. The program is complete except that I have removed the body of the method for find. Given the following class for the nodes in...
1. Write an INSERT statement that adds this row to the Categories table: CategoryName: Brass Code the INSERT statement so SQL Server automatically generates the value for the CategoryID column. 2. Write an UPDATE statement that modifies the row you just added to the Categories table. This statement should change the Category Name column to “Woodwinds”, and it should use the CategoryID column to identify the row. 3.Write an INSERT statement that adds this row to the Products table: ProductID:...
write a C program to make the dictionary USING LINKED LISTS and STORE DATA in File HANDLING..... you have to create functions 1. insert 2. delete 3. search(if we search with any letter then the words with same first letter have been shown) 4. display 6. exit Appearance should be like proper dictionary.
Number Name 3. Assuming no page fault on a page table access, what is the processor memory access time for the system depicted in the above figure, for a physical memory with 50ns read/write times? 4. Now, assume that the memory system has a translation look-aside buffer (TLB). The TLB requires 10 ns to determine a hit or mess. The physical memory system has an access time of 50ns. You may assume that page fault rate for the application is...
Problems and Exercises 1 through 9 are based on the dass scheduling 3NF relations along with some sample data shown in Figure 6-11. Not shown in this figure are data for an ASSIGNMENT relation, which represents a many-to-many relationship between faculty and sections.4. Write SQL data definition commands for each of the following queries:a. How would you add an attribute, Class, to the Student table?b. How would you remove the Registration table?c. How would you change the FacultyName field from...
Can you please help with the below? 1) Which of the following is true about using a 2-3-4 tree? a. It is designed to minimize node visits while keeping to an O(log n) search performance b. It is designed to self-balance as new values are inserted into the tree c. As soon as a node becomes full, it performs the split routine d. None of the above 2) Which of the following is true about a binary search tree? a. ...
CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE IF POSSIBLE!! General Description: Write a program that allows the user to enter data on their friends list. The list holds a maximum of 10 friends, but may have fewer. Each friend has a name, phone number, and email address. The program first asks the user to enter the number of friends (1-10). You are not required to validate the entry, but you may...
Codelab question! This is c++. Consider the following code: // Linked Lists: TRAVERSE struct ListNode { int data; struct ListNode *next; }; Assume that a linked list has been created and head points to a sentinel node. A sentinel node is an empty data node in the beginning of the list. It sometimes holds a sentinel value. The use of sentinel nodes is a popular trick to simplify the insert and delete operations. You may also assume that the list...
Write a C program that will act as a database access tool. Three separate functions are needed to: 1. Print dates 2. Print names 3. Print category numbers and the average of the numbers. A random text file (from notepad) is supplied for the dates, names, and category's. For Example: Storm name: Storm Date: Storm category number: The program must ask the user which of the three items listed above they want to run instead of dumping all of the...