Global It Leader!!



 
 

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

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 10,843회 작성일 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 오피스팁에서 이동 됨]

댓글목록

등록된 댓글이 없습니다.

전체 440
게시물 검색
컴퓨터언어 목록
번호 제목 글쓴이 조회 날짜
240 그누보드스킨 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4496 08-20
239 CSS no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4840 08-19
238 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4997 07-29
237 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4663 07-26
236 그누보드스킨 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5019 06-24
235 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4607 06-20
234 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4657 05-20
233 PHP no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4842 04-11
232 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4400 04-11
231 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5146 03-28
230 그누보드스킨 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4961 03-27
229 그누보드스킨 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4550 03-26
228 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4537 03-20
227 그누보드스킨 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4931 03-20
226 그누보드스킨 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4472 03-13
225 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4745 03-09
224 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4912 03-09
223 CSS no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4619 03-08
열람중 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10844 06-30
221 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 6709 06-25