0% found this document useful (0 votes)
72 views4 pages

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

This document discusses building a C# Windows Forms application that connects to a SQL Server database. It includes code to: 1. Design the database with fields like name, major, and semester. 2. Design the Windows Forms interface to match the database structure with textboxes, buttons, and a datagridview. 3. Write C# code behind the form to perform CRUD operations on the database like inserting, updating, deleting records and displaying them in the datagridview by connecting to the database and executing SQL commands.

Uploaded by

AliBasriadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
72 views4 pages

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

This document discusses building a C# Windows Forms application that connects to a SQL Server database. It includes code to: 1. Design the database with fields like name, major, and semester. 2. Design the Windows Forms interface to match the database structure with textboxes, buttons, and a datagridview. 3. Write C# code behind the form to perform CRUD operations on the database like inserting, updating, deleting records and displaying them in the datagridview by connecting to the database and executing SQL commands.

Uploaded by

AliBasriadi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
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 System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using 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