웹프로그래밍

Global It Leader!!


컴퓨터언어


 
 

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

페이지 정보

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

댓글목록

등록된 댓글이 없습니다.

전체 441
게시물 검색
컴퓨터언어 목록
번호 제목 글쓴이 조회 날짜
열람중 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 11248 06-30
220 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7115 06-25
219 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7933 06-25
218 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8470 06-25
217 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 13427 06-24
216 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8960 06-24
215 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9643 06-17
214 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 25520 07-22
213 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10306 07-21
212 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8787 07-21
211 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9138 07-21
210 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8553 07-20
209 VB no_profile 운영자 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10443 07-15
208 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8537 07-14
207 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7831 07-14
206 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9394 07-13
205 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9419 07-13
204 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8005 07-08
203 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 7650 07-08
202 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9039 07-08