0% found this document useful (0 votes)
38 views

Modul C# Database SQL, Connection, Manipulasi Data Dan Report

This document discusses creating a C# Windows Forms application to manage a SQL Server database. It includes: 1. Designing a database in SQL Server with fields like name, major, and semester. 2. Designing a Windows Forms interface to connect to the database, perform CRUD operations, and display data in a datagrid. 3. Listing the C# code for the Windows Forms application which connects to the database, executes SQL commands to insert, update, delete and retrieve data, and loads data into the datagrid.

Uploaded by

mifjani
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Modul C# Database SQL, Connection, Manipulasi Data Dan Report

This document discusses creating a C# Windows Forms application to manage a SQL Server database. It includes: 1. Designing a database in SQL Server with fields like name, major, and semester. 2. Designing a Windows Forms interface to connect to the database, perform CRUD operations, and display data in a datagrid. 3. Listing the C# code for the Windows Forms application which connects to the database, executes SQL commands to insert, update, delete and retrieve data, and loads data into the datagrid.

Uploaded by

mifjani
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Modul C# Database SQL, Connection,manipulasi data dan Report

1. Rancanglah Database pada Sql Server dengan field seperti dibawah ini.

2. Rancanglah tampilan interface pada lingkungan windows C# .Net seperti dibawah ini sesuai dengan database yang anda buat

Listing Program
using using using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; System.Data.SqlClient;

namespace lat_c_shap { public partial class Form1 : Form { public SqlConnection con1; public SqlCommand com1, com2; public SqlDataAdapter adp1; public DataSet ds1; public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // TODO: This line of code loads data into the 'ds1.tbmhs' table. You can move, or remove it, as needed. this.tbmhsTableAdapter1.Fill(this.ds1.tbmhs); string cstr; cstr = "Data Source=ZEBAOTH-779C970;Initial Catalog=pop;Integrated Security=True"; con1 = new SqlConnection(cste); con1.Open(); com1 = new SqlCommand(); com1.Connection = con1; com1.CommandType = CommandType.Text; ds1 = new DataSet(); adp1 = new SqlDataAdapter(com1); adp1.Fill(ds1, "tbmhs"); dg1.DataSource = ds1; dg1.DataMember = "tbmhs"; con1.Close(); } private void BtnClear_Click(object sender, EventArgs e)

{ this.txtnim.Clear(); this.txtnama.Clear(); this.txtjurusan.Clear(); this.txtsemester.Clear(); } private void BtnDelete_Click(object sender, EventArgs e) { con1.Open(); com1 = new SqlCommand(); com1.Connection = con1; com1.CommandType = CommandType.Text; com1.CommandText = "delete from tbmhs where nim='" + this.txtnim.Text + "'"; com1.ExecuteNonQuery(); com2 = new Sqlcommand(); com2.Connection = con1; com2.CommandType = CommandType.Text; com2.CommandText = "Select * from tbmhs"; ds1 = new DataSet(); adp1 = new SqlDataAdapter(com2); adp1.Fill(ds1, "tbmhs"); dg1.DataSource = ds1; dg1.DataMember = "tbmhs"; con1.close(); this.dg1.Refresh(); } private void BtnAdd_Click(object sender, EventArgs e) { con1.Open(); com1 = new SqlCommand(); com1.Connection = con1; com1.CommandType = CommandType.Text; com1.CommandText = "insert into tbmhs values ('" + txtnim.Text + "','" + txtjurusan.text + "','" + txtsemester.text + ")"; com1.ExecuteNonQuery(); com2 = new Sqlcommand(); com2.Connection = con1; com2.CommandType = CommandType.Text; com2.CommandText = "Select * from tbmhs"; ds1 = new DataSet(); adp1 = new SqlDataAdapter(com2); adp1.Fill(ds1, "tbmhs"); dg1.DataSource = ds1; dg1.DataMember = "tbmhs"; con1.Close(); this.dg1.Refresh(); } private void btnUpdate_Click(object sender, EventArgs e) {

con1.Open(); com1 = new SqlCommand(); com1.Connection = con1; com1.CommandType = CommandType.Text; com1.CommandText = "update tbmhs set nama='" + txtnama.text + "',jurusan= " + txtjurusan.text + ",semester=" + txtsemester.text + " where nim ='" + txtnim.text + "'"; com1.ExecuteNonQuery(); com2 = new Sqlcommand(); com2.Connection = con1; com2.CommandType = CommandType.Text; com2.CommandText = "Select * from tbmhs"; ds1 = new DataSet(); adp1 = new SqlDataAdapter(com2); adp1.Fill(ds1, "tbmhs"); dg1.DataSource = ds1; dg1.DataMember = "tbmhs"; con1.Close(); this.dg1.Refresh(); } private void BtnFind_Click(object sender, EventArgs e) { con1.Open(); com1 = new SqlCommand(); com1.Connection = con1; com1.CommandType = CommandType.Text; com1.CommandText = "select * from tbmhs"; ds1 =new DataSet(); //com1.ExecuteNonQuery(); //com2 = new Sqlcommand(); //com2.Connection = con1; //com2.CommandType = CommandType.Text; //com2.CommandText = "Select * from tbmhs"; ds1 = new DataSet(); adp1 = new SqlDataAdapter(com1); adp1.Fill(ds1, "tbmhs"); DataTable tbmhs = ds1.Tabel["pop"]; DataColumn[] col1= new DataColumn[1]; col1[0]=tbmhs.Columns["nim"]; tbmhs.PrimaryKey=col1; DataRow rw1=tbmhs.Rows.Find(txtnim.Text); txtnim.Text=(string)rw1 ["nim"]; txtnama.Text=(string)rw1 ["nama"]; int A =(int)rw1 ["jurusan"]; txtjurusan.Text =A.ToString(); int B =(int)rw1 ["semester"]; txtsemester.Text =B.ToString(); //report variabel = new report(); //variabel.MdiParent = form1; //variabel.Show(); } } }

You might also like