코스웨어/15년 스마트컨트롤러
20150619-5번-김성주-ADO.NET /
알 수 없는 사용자
2015. 6. 19. 09:26
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