Database dengan SQL SERVER 2008 R2 dan c# dengan Microsoft Visual Studio 2010 Service Pack 1
USE [rusdhaRS]
GO
/****** Object: Table [dbo].[rs_pegawai] Script Date: 03/11/2016 06:43:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[rs_pegawai](
[id_pegawai] [int] IDENTITY(1,1) NOT NULL,
[nip] [varchar](50) NULL,
[nama] [varchar](50) NULL,
[tempat_lahir] [varchar](50) NULL,
[tanggal_lahir] [datetime] NULL,
[jenis_kelamin] [char](6) NULL,
[alamat] [varchar](200) NULL,
[provinsi] [varchar](100) NULL,
[kota] [varchar](100) NULL,
[tlp] [char](15) NULL,
CONSTRAINT [PK_rs_pegawai_1] PRIMARY KEY CLUSTERED
(
[id_pegawai] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
Setelah DB sudah dibuat kita buat kelas koneksinya dahulu codenya dibawah ini
koneksi.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace rusdhaRS
{
class koneksi
{
SqlConnection con;
SqlCommand cmd;
SqlDataAdapter da;
public koneksi()
{
this.con = new SqlConnection(@"uid=sa;pwd=l3pt0pku;initial catalog=rusdhaRS;data source=.");
}
public DataTable execQueryProc(string sql, object[] values)
{
this.con.Open();
this.cmd = new SqlCommand();
this.cmd.Connection = this.con;
try
{
this.cmd.CommandType = CommandType.StoredProcedure;
this.cmd.CommandText = sql;
if (values != null)
{
int prmIndex = 0;
SqlCommandBuilder.DeriveParameters(this.cmd);
foreach (SqlParameter prm in this.cmd.Parameters)
{
if (prm.Direction == ParameterDirection.Input)
{
prm.Value = values[prmIndex];
prmIndex++;
}
}
}
this.da = new SqlDataAdapter(this.cmd);
DataTable dt = new DataTable("data");
this.da.Fill(dt);
return dt;
}
catch (Exception ex)
{
throw ex;
}
finally
{
this.cmd.Dispose();
this.cmd = null;
//this.da.Dispose();
//this.da = null;
if (this.con.State == ConnectionState.Open)
this.con.Close();
}
}
}// end class
}//end namespace
Setelah kelas koneksi udah dibuat saatnya kita buat model kelas property get; set;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace rusdhaRS.model
{
public class rs_pegawai
{
public int id_pegawai { get; set; }
public string nip { get; set; }
public string nama { get; set; }
public string tempat_lahir { get; set; }
public DateTime tanggal_lahir { get; set; }
public string jenis_kelamin { get; set; }
public string alamat { get; set; }
public string provinsi { get; set; }
public string kota { get; set; }
public string tlp { get; set; }
}
}
Setelah semua dibuah anda harus buat Winform nya kayak gini
NEXT POSTING.. #2 LAST POSTING.. #3
thanks min sudah share, bermanfaat sekali...
ReplyDeletehttp://www.mmionline.net/