Global It Leader!!



 
 

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

페이지 정보

작성자 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 10,844회 작성일 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 PHP no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4603 08-28
239 그누보드스킨 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4497 08-20
238 CSS no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4841 08-19
237 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4998 07-29
236 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4664 07-26
235 그누보드스킨 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5020 06-24
234 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4608 06-20
233 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4658 05-20
232 PHP no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4844 04-11
231 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4402 04-11
230 Mysql no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 5147 03-28
229 그누보드스킨 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4963 03-27
228 그누보드스킨 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4551 03-26
227 Javasript no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4539 03-20
226 그누보드스킨 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4933 03-20
225 그누보드스킨 no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4474 03-13
224 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4746 03-09
223 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4912 03-09
222 CSS no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 4620 03-08
열람중 VB no_profile 오원장 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10845 06-30