Global It Leader!!



 
 

VB C#, VB에서 MySQL 사용하기

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 10,842회 작성일 10-06-30 14:13

본문

1. C# , VB에서 MySQL DB 연동을 사용하려면 .Net Connecter 를 설치해야한다.


2. Visual C#, VB 2008을 실행한후 메뉴중 프로젝트 > 참조추가 > 찾아보기 > 경로 “C:\Program Files\MySQL\MySQL Connector Net 5.1.5\Binaries\.NET 2.0″ 에서 ‘MySql.Data.dll’ 을 지정해 준다.
[C#]
Form.cs 코드 편집창에 ‘using MySql.Data.MySqlClient;’ 을 추가한다.
[예제] MySQL 접속과 DB 변경, DB 접속상태, 자료입력에 대한 예
private void button1_Click(object sender, EventArgs e)
{
MySqlConnection myConnection = new MySqlConnection();
myConnection.ConnectionString = “Persist Security Info=False;database=디비명;server=localhost;Connect Timeout=30;user id=아이디; pwd=비번”;
myConnection.Open();
MessageBox.Show(”Server Version: ” + myConnection.ServerVersion + “\nDatabase: ” + myConnection.Database);
myConnection.ChangeDatabase(”dbs”);
MessageBox.Show(”ServerVersion: ” + myConnection.ServerVersion + “\nDatabase: ” + myConnection.Database);
MessageBox.Show(”ServerVersion: ” + myConnection.ServerVersion + “\nState: ” + myConnection.State.ToString());
myConnection.Close();
// 자료입력
InsertData();
}
public void InsertData()
{
MySqlConnection myConnection = new MySqlConnection();
myConnection.ConnectionString = “Persist Security Info=False;database=디비명;server=localhost;Connect Timeout=30;user id=아이디; pwd=비번”;
myConnection.Open();
string myInsertQuery = “INSERT INTO info (name, id, pass) Values(’이름’, ‘myid’, 1234)”;
MySqlCommand myCommand = new MySqlCommand(myInsertQuery);
myCommand.Connection = myConnection;
myCommand.ExecuteNonQuery();
myCommand.Connection.Close();
}
[VB] Form1.vb 코드편집창에 ‘Imports MySql.Data.MySqlClient’ 을 추가한다.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myConnection As New MySqlConnection()
myConnection.ConnectionString = “Persist Security Info=False;database=디비명;server=localhost;Connect Timeout=30;user id=아이디; pwd=비번”
myConnection.Open()
End Sub
End Class

출처 : http://study4u.justgoo.com/forum-f8/topic-t327.htm
[이 게시물은 오원장님에 의해 2013-02-28 16:42:35 오피스팁에서 이동 됨]

댓글목록

등록된 댓글이 없습니다.

전체 95
게시물 검색
컴퓨터언어 목록
번호 제목 글쓴이 조회 날짜
55 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6322 12-16
54 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4449 11-14
53 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8855 11-05
52 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4624 10-24
51 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7111 10-24
50 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4662 07-26
49 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4744 03-09
48 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4910 03-09
열람중 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10843 06-30
46 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6707 06-25
45 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7469 06-25
44 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8033 06-25
43 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 13004 06-24
42 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8538 06-24
41 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9231 06-17
40 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 24953 07-22
39 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9921 07-21
38 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8410 07-21
37 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8724 07-21
36 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8113 07-20