728x90
반응형
C# - ADO.NET & 인명부
인명부 만들기
<코드 구현>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb; //OleDbConnection,OleCommand 클래스 등 사용
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
private string StrSQL =
//데이터베이스 연결 문자열
@"Provider=Microsoft.ACE.OLEDB.12.0;" +
"Data Source=Human.accdb;Mode=ReadWrith";
private string Human_Name, Human_Phone;//선택된 컨트롤에 행의 값을 저장
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
lvList_OleDb_View();
}
private void lvList_OleDb_View()
{
this.lvList.Items.Clear();
var Conn = new OleDbConnection(StrSQL);
Conn.Open();
var Comm = new OleDbCommand("SELECT * FROM HmanInfo", Conn);
var myRead = Comm.ExecuteReader();
while(myRead.Read())
{
var strArray = new String[]{myRead["M_Name"].ToString(),
myRead["M_Age"].ToString(),myRead["M_Phone"].ToString()};
var lvt = new ListViewItem(strArray);
this.lvList.Items.Add(lvt);
}
myRead.Close();
Conn.Close();
}
private void btnSave_Click(object sender, EventArgs e)
{
if(Control_Check()==true)
{
var Conn = new OleDbConnection(StrSQL);
Conn.Open();
string Sql = "INSERT INTO HumanInfo(M_Name,M_Age,M_Phone)";
Sql += "VALUES(" + this.txtName.Text + ",";
Sql += this.txtAge.Text + "," + this.txtCellPhone.Text + ")";
var Comm = new OleDbCommand(Sql.Conn);
int i = Comm.ExecuteNonQuery();
Conn.Close();
if (i == 1)
{
MessageBox.Show("정상적으로 데이터가 저장되었습니다.", "알림",
MessageBoxButtons.OK, MessageBoxIcon.Information);
lvList_OleDb_View();
Control_clear();
}
else
{
MessageBox.Show("정상적으로 데이터가 저장되지 않았습니다.",
"에러", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private bool Control_Check()
{
throw new NotImplementedException();
}
private void btnModify_Click(object sender, EventArgs e)
{
if (Control_Check() == true)
{
var Conn = new OleDbConnection(StrSQL);
Conn.Open();
string Sql = "UPDATE HumanInfo SET M_Name=" + this.txtName.Text +
",M_Age=" + Convert.ToInt32(this.txtAge.Text);
Sql += ",M_Phone=" + this.txtCellPhone.Text + "";
Sql += "WHERE M_Name=" + this.Human_Name +
"AND M_Phone=" + this.Human_Phone + "";
var Comm = new OleDbCommand(Sql.Conn);
int i = Comm.ExecuteNonQuery();
Conn.Close();
if (i == 1)
{
MessageBox.Show("정상적으로 데이터가 수정되었습니다.", "알림",
MessageBoxButtons.OK, MessageBoxIcon.Information);
lvList_OleDb_View();
Control_clear();
}
else
{
MessageBox.Show("정상적으로 데이터가 수정되지 않았습니다.",
"에러", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void lvList_DataSet_View()
{
this.lvList.Items.Clear();
var Conn = new OleDbConnection(StrSQL);
Conn.Open();
var OleAdapter = new OleDbDataAdapter(
"SELECT * FROM HumanInfo", Conn);
DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("dsTable");
OleAdapter.Fill(ds,"dsTable");
IEnumerable<DataRow> query=
from HumanInfo in dt.AsEnumerable()
select HumanInfo;
foreach(DataRow HumData in query)
{
var strArray = new String[]{HumData.Field<string>("M_Name"),
HumData.Field<int>("M_Age").ToString(),
HumData.Field<string>("M_Phone")};
this.lvList.Items.Add(new ListViewItem(strArray));
}
Conn.Close();
}
private void btnDel_Click(object sender, EventArgs e)
{
if (Control_Check() == true)
{
var Conn = new OleDbConnection(StrSQL);
Conn.Open();
string Sql = "DELETE FROM HumanInfo WHERE M_Name=" +
this.Human_Name + "AND M_Phone=" + this.Human_Phone + "";
Sql += "VALUES(" + this.txtName.Text + ",";
Sql += this.txtAge.Text + "," + this.txtCellPhone.Text + ")";
var Comm = new OleDbCommand(Sql.Conn);
int i = Comm.ExecuteNonQuery();
Conn.Close();
if (i == 1)
{
MessageBox.Show("정상적으로 데이터가 저장되었습니다.", "알림",
MessageBoxButtons.OK, MessageBoxIcon.Information);
lvList_OleDb_View();
Control_clear();
}
else
{
MessageBox.Show("정상적으로 데이터가 저장되지 않았습니다.",
"에러", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void lvList_DataSetRamda_view()
{
this.lvList.Items.Clear();
var Conn = new OleDbConnection(StrSQL);
Conn.Open();
var OleAdapter = new OleDbDataAdapter(
"SELECT * FROM HumanInfo",Conn);
DataSet ds = new DataSet();
DataTable dt = ds.Tables.Add("dsTable");
OleAdapter.Fill(ds,"dsTable");
var query = dt.AsEnumerable().
Select(HumanInfo => new
{
Name = HumanInfo.Field<string>("M_Name"),
Age = HumanInfo.Field<int>("M_Age").ToString(),
Phone = HumanInfo.Field<string>("M_Phone")
});
foreach(var HumData in query)
{
var strArray = new String[]{HumData.Name,HumData.Age,
HumData.Phone};
this.lvList.Items.Add(new ListViewItem(strArray));
}
Conn.Close();
}
private void lvList_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
-----------------------------------------------------
C++ - string
string.h파일 안에 있는 내용을 확인하는 간단한 예제
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
string obj("하이");
string obj1("test");
obj=obj+obj1;
cout << obj.length()<<endl;
return 0;
}
728x90
'코스웨어 > 15년 스마트컨트롤러' 카테고리의 다른 글
20150626-11번-남수진 MySQL/클래스템플릿의 정적 멤버 변수 (6) | 2015.06.26 |
---|---|
20150625 업무일지 출석번호 9번 김태현 (10) | 2015.06.25 |
20150624-8번-김태영-MySQL 비쥬얼스튜디오 연동, 클래스 템플릿 (6) | 2015.06.24 |
20150623-7번-김재홍-MySQL설치(C#)_템플릿의 개념(C++) (7) | 2015.06.24 |
20150618 4번 김민정 C#(str 연산자, Str 연산자, 다형성) (2) | 2015.06.19 |
20150618 4번 김민정LINQ(groupby, join, LINQ를 사용한 성적처리 프로그램) (2) | 2015.06.19 |
20150617-3번-권오민 - LINQ / 가상함수(virtual)&연산자 오버로딩(+=, [ ], ->) (13) | 2015.06.17 |
2015.06.17 졸업생과의 만남 ^^ (16) | 2015.06.17 |