Laman

Sabtu, 27 Agustus 2011

koneksi C# dengan SQL SERVER dan mengambil data dari SQL SERVER

SQL server merupakan DBMS yang powerfull, DBMS ini banyak digunakan untuk kalangan komputer SERVER karena kemampuan, fitur dan recovery data yang sangat baik sekali, SQL server adalah DBMS yang dikembangkan oleh perusahaan raksasa software Micorosoft cooporation. DBMS ini sengaja dikembangakan untuk keperluan bisnis, berbeda dengan DBMS MYSQL, skala SQL server jauh lebih besar. Pada tutorial sebelumnya dibahas tentang cara koneksi C# dengan DBMS MYSQL serta cara melakukan load data dan manipulasi data (Insert, update, delete), pada kesempatan ini akan dibahas tentang bagaimana cara mengkoneksikan C# dengan DBMS SQL Server beserta  cara pengambilan data dari SQL server ke aplikasi C#. Berikut ini adalah langkah-langkah untuk melakukan koneksi dengan DBMS SQL Server. Pertama siapkan project kosong, pada IDE Visual Studio klik file pilih new project, muncul kotak dialog save project, beri nama project sesuai dengan keinginan dan klik OK. Untuk langkah demi langkah selanjutnya ikuti intruksi dibawah ini
langkah 1 : tambahkan control Datagridview dan button. Atur dan tata sedemikian rupa sehingga tampilannya seperti pada gambar dibawah ini



langkah 2 : tambahkan library SQL client pada header program, berikut adalah source code lengkapnya




langkah 3 : double klik pada button1 (button yang berlabelkan Load Data) untuk membangkitkan event single klik pada button tersebut, masukan script code berikut ini. Untuk lebih jelasnya tentang macam macam event klik disini



langkah 4: done, program selesai dibuat. Jika langkah langkah diatas dilakukan dengan benar, maka saat program dijalankan program akan menampilakan datagridview kosong dengan satu button, ketika button tersebut diklik maka semua data yang ada pada table yang dipilih akan diload ke datagrid view. berikut ini adalah preview program yang telah dirunning. Saat program pertama kali dijalankan


ketika button Load Data ditekan, hasilnya adalah seperti berikut ini
Gambar 2. Preview running program

jika diperhatikan ukuran kolom pada datagird sama lebarnya, untuk mempercantik datagridview dengan merubah masing masing ukuran lebar kolom, tambahakn scrip dibawah ini pada akhir event single klik pada button LoadData
  

source code diatas digunakan untuk mengatur lebar masing masing kolom yang telah ditentukan, setelah source code diatas ditambahkan hasilnya adalah seperti berikut ini

Gambar 3. Preview running program 
 
perhatikan potongan source code diatas, pada SQLSERVER ada dua cara untuk melakukan login, yang pertama menggunakan akun SQL SERVER yang kedua menggunakan akun Windows anda, ini penting untuk diketahui karena kaitannya dengan proses pembentukan string koneksi, untuk lebih jelasnya tentang string koneksi klik disini

pada tutorial ini digunakan proses login dengan autentifikasi dari akun windows, bukan dari akun SQL SERVER, untuk download file databanya silahkan download disini.

download binary file disini
download full project disini
download file database disini

NB : Dalam tutorial ini program ditulisa menggunakan IDE Visual studio 2010. dengan target framework 2.0 . Sehingga minimal komputer harus terinstal windows xp untuk bisa menjalankan program *.exe nya, Sedangkan untuk membuka projectnya mau tidak mau harus menginstal microsoft visual studio 2010

46 komentar:

  1. minta source code koneksi database SQLServer, seperti membuka koneksi, command, update delete insert dan menggunakan datagrid view, buat referensi projek mata kuliah Rapid Application development

    BalasHapus
  2. semua link project sudah ada di artikel ini, cek lagi ya... :-D

    BalasHapus
  3. Lam Kenal Gan (Admin) slama ini ane belajar C# dari Posting ente dan hasilnya-pun cukup memuaskan buat ane memperdalaminya :-)

    Sehubungan dengan posting kali ini, ane juga minat memakai C# dengan SQL Server yang telah tersedia dalam VS-nya, tapi ada sedikit kesulitan untuk cara menggunakannya.
    Mohon share-nya untuk aplikasi C# dan SQL Server (dari VS-nya) dengan Objek Btn Insert, Edit, Search, Delete, Show to Datagridview (TextBox).

    Di tunggu share posting terbarunya dengan reques ane :-)
    Thank's

    BalasHapus
  4. thanks....
    ayo.. semangat belajar.. trus......

    BalasHapus
  5. Terimakasih, semoga bisa bermanfaat...
    amin...

    BalasHapus
  6. bang admin begini..
    saya pakai Microsft SQL server 2008R2 nah untuk koneksinya bagaimana tuhh?
    saya coba yang di atas dengn menyesuaikan dari mulai datasource dan initial catalognya saya sudah set sesuai settingan di MSQL saya tapi tetap saja tidak konek..
    mohon pencerahannya..
    dan seandanya bisa kirim ke e-mail saya bang.. di irwan.nawo.suwandi@gmail.com
    terimakasih banyakk..
    maju terus csharp-indonesia..

    BalasHapus
  7. untuk masalah error pertama harus diketahui dulu error messegenya apa.?
    karena error messege dalam sebuah pemrograman atau konsep DBMS sangat membatu bagi para programer untuk melacak dimanakah letak error dari source code nya,
    disini kalau boleh tahu, error messegenya bagaimana?

    BalasHapus
  8. Untuk koneksi Sql server multi user bagaimana caranya, maksudnya gni misalnya saya punya 2 komputer yang sudah konek satu sama lain, komputer 1 di beri SQL Server 2000 komputer 2 tidak, trus agar komputer 2 bisa terhubung ke Database komputer 1 bagaimana caranya, koneksi ke database menggunakan apa

    BalasHapus
  9. kalau permasalahan seperti itu adalah masalah jaringan dan database, kalau untuk itu silahkan baca tutorial nya dari link dibawah ini

    http://social.msdn.microsoft.com/Forums/en-US/sqldataaccess/thread/3aa5854e-85cc-4851-a1bd-9ed1a3ad08cd/

    semoga bisa membantu dan bermanfaat

    BalasHapus
  10. terima kasih ... artikel nya sangat membantu saya untuk mengerjakan tugas besar kuliah. :) . keep posting and i wanna be a stalker :)

    BalasHapus
  11. om, kalau coding buat Simpan, kaya gimana om, mohon pencerahanya

    BalasHapus
  12. Terimakasih, semoga bisa bermanfaat dan membantu

    BalasHapus
  13. Untuk melakukan insert, Update maupun Delete yang perlu diperhatikan adalah pada Querynya, karena secara keseluruhan koneksi semua DBMS pada C# ataupun dotnet mempunyai struktur yang sama. hanya saja proses Read dan Write Sedikit agak berbeda. silahkan baca artikel di Blog ini. silahkan dibaca pada artikel ini http://www.csharp-indonesia.com/2011/06/load-data-dari-mysql-dan-insert-data-ke.html walapun itu menggunakan MYSQL tetapi secara konsep sama.

    BalasHapus
  14. Ada lg Ga gan Link yg membahas tentang C# ke SQL Server

    BalasHapus
  15. memang untuk SQL server agak jarang dibahas. karena kebanyak dalam dunia akademik menggunakan DBMS MYSQL, jadi lebih banyak membahas tentang MYSQL

    BalasHapus
  16. tambahin donk supaya lebih banyak lgi nih . . .

    BalasHapus
  17. mas, failed login itu yang ditrace bagian mana?perasaan sudah benar konfigurasinya.
    mohon pencerahannya

    BalasHapus
  18. kalau boleh tau error messegenya bagaimana...???

    BalasHapus
  19. SQL Server 2008 harus dikoneksi dengan menggunakan port tertentu, tentukan port di SQL Server Configuration Contoh : 192.168.100.1,1500. terus di Firewall buat port yang diijinkan masuk, misal nama PORT-nya SQL Server dengan nilai port 1500 (ini untuk di winXP)

    BalasHapus
  20. Apakah bisa minta database tsb yg sudah jadi.

    BalasHapus
  21. bang bagaimana cara menampilkan data di datagridview menggunakan sqlserver 2005

    BalasHapus
  22. makasih mass infonya..
    info seputar bola, prediksi bola ter-update..
    berita bola TERBARU DAN TERPERCAYA hanya ada di www.bola368.net

    BalasHapus
  23. cara membuka database mysql dari kmputer lain gmna ya..jadi saya mau buat clien server clientnya gmna caranya bisa akses atau melihat databasenya? makasih

    BalasHapus
  24. as well as for the upcoming Fall-Winter. The cocktail event took place at Edelman PR office (the PR sunglass hut firm that handles Oakley’s public relations in Canada) at 150 Bloor Street West in Toronto. Fashion media from Toronto could get a sneak peak at Oakley’s high performance and versatile fitness apparel and sunglasses, as well as their fashionable Summer and Fall lifestyle oakley military apparel line for both men and women. Guests could view the latest fashion and fitness trends, learn about unique Oakley apparel technology, and find out about the newest pieces from Oakley’s brand representatives.Oakley sunglasses are designed with a unique technology that provides more oakley gascan efficiency during sports activities, like jogging. Most of the times, when we go in the park for jogging, it’s not that comfortable for us to wear sunglasses (even though it would be useful), due to the fact that our face sweats five minutes oakley prescription sunglasses into jogging and the sunglasses slip off our nose. One of the styles of Oakley sunglasses are designed in such a way that not only don’t they fall off the face, but they actually stick to the skin when sweaty, making wearing sunglasses oakley holbrook during jogging more comfortable and efficient.
    Sunglasses and their accessories can be a great holiday gift for the hard-to-please or for the person who has everything. Gift certificates to any of these stores are available in any denomination for purchase. Give a gift oakley sports sunglasses that gives them the control, while giving you the ease with shopping and peace of mind.Glasses.com, an online retailer of prescription and non-prescription designer glasses and sunglasses, is having a huge sale on Cyber Monday, December 1, 2014 (expires 11:59 p.m. MST)! Hurry orange oakley sunglasses and take advantage of this one day only secret sale at Glasses.com and enjoy up to 70 percent off! Choose from a wide-range of styles and designer brands such as, but not limited to: Burberry, Kate Spade New York, Lanvin, Maui Jim, Oakley, radar oakley sunglasses Persol and Ray-Ban!
    $25 - $75 Price Point

    BalasHapus
  25. “It says, ‘I’m not Ray-Ban, I’m Blakened,” says Hinton.24DP, an award winning Greenwich Village-based production company and creative group, formally announced its expansion into a full service advertising agency today. The firm’s new addition to its business model will provide advertisers with a welcomed alternative to large and costly agencies that are synonymous with Madison Avenue.In a press statement, CEO Brian ray bands Cristiano, a 2008 New York Emmy? award winner [Advanced Media: Commercial] acknowledges “it is a fact that large advertising agencies have massive overhead and that their clients pay for it directly.” These high ray ban sunglasses womens operational costs are directly correlated to their reliance upon third party vendors for production and creative services. As 24DP will now function as an all-in-one advertising, creative and production house, clients will ray ban reading glasses doubtlessly benefit from its streamlined and very cost effective services; all campaign elements – from conceptualization to execution, and everything in between – will be handled in-house, saving businesses time and money, while ray ban men sunglasses maximizing ROI and leveragability.
    As the sun warms up for the summer, get inspired by Michelle easy chic style.There were several eyewear suppliers with music tie-ins at the recent International Vision Expo & RB3467 Conference trade show at New York’s Javits Center, but none more musically inclined than Spokane-based Davesh’s new Blakened line for men.Indeed, Blakened is “inspired by music,” notes Davesh executive vice president of marketing ray ban sunglasses clubmaster and sales Doug Hinton, and “the lasting impression it leaves on each of our lives. Our brand aspires to do the same in eyewear.”Blakened’s marketing tag line, in fact, is “for the love ray ban wayfarer 2 of music,” and Blakened pieces each bear a tiny guitar pic logo on the left temple.“We love music,” notes Hinton. He reiterates: “As you know, it can leave a lot of impressions on polarized sunglasses ray ban people: A song can take you back 20 years or 50 years, and we want to leave the same lasting impression on our customers.”
    “Breaking the rules or being rude will not get ray ban cockpit sunglasses businesses excited about Glass and will ruin it for other Explorers.”In fact, some businesses have already responded negatively, by banning the use of Google Glass in some San Francisco bars due to real ray bans eyeglasses concerns of privacy with other patrons.

    BalasHapus
  26. Today, Electric Daisy is a weeklong event that includes celebrity DJ parties at resorts such as the Wynn Las Vegas and a two-day conference on the dance music business at the Cosmopolitan of Las Vegas, owned by the Blackstone Group. “Now they put us on their marquees,” Rotella says of the casinos.A number of Ray Ban Wayfarer blue chip investors and advertisers are backing the Rock in Rio festival, which held its first event in Brazil 30 years ago. SFX Entertainment, which co-owns the festival globally, is staging the $75 million event alongside local partners Cirque du Soleil and Ron Burkle, the billionaire Los Angeles investor. Rock in Rio has sold almost $15 million in sponsorships Oakley Eyeglasses to 63 companies including Mercedes-Benz, Corona beer, and Chilli Beans sunglasses.
    "He said, 'I needle you guys out of affection,'" Wallsten said. "I said, 'I understand that, but I don't want you to treat me any differently because of this."'Wallsten said the president said he would not treat him differently, so Wallsten encouraged him to "needle away.""He said, 'I Cheap Oakley Sunglasses will. Next time I'll just use a different needle,'" Wallsten said.Wallsten said he thought that was a pretty good line. And his only complaint is that the president didn't answer his question at the news conference.Wallsten, who is also author of a book coming out next month titled "One Party Country: The Republican Plan for Dominance in the 21st Ray-Ban Sunglasses Century," had asked about White House credibility now in the aftermath of top aide Karl Rove having been cleared in the CIA leak investigation. But Mr. Bush said he wouldn't comment with another top White House aide still facing prosecution in the case. Sunglasses are the must-have accessory for summer. But with so many shapes and styles to choose Oakley Outlet from, it's sometimes hard to determine what's right for you. Never fear, "Early Show" Style Contributor Katrina Szish has the perfect sunglasses for everyone. Szish says it is important to first determine your face shape to steer yourself towards a trend that works for you. NEW YORK -- Before you plunk down $500 for a pair of prescription eyeglasses, oakley polarized you might consider getting them online.
    “People are starting to look at sunglasses differently, as a more premium accessory,” says Hansen, whose stores offer visitors complimentary drinks and chocolates while they shop.That’s why it’s important to find a pair that suits your face shape. The size of your sunglasses should be proportional to your face size. It’s important to Ray-Ban look for frames that complement a face by softening or drawing attention away from its more prominent features. Lozac’h, for example, needed a frame that would widen his long face. Don’t look for larger frames if you have a small face and vice versa. Oval-shaped faces are symmetrical, so most styles will work. These lucky few can experiment with oakley batwolf different shapes, styles and colors.
    "UV protection is very, very important. It's like you wouldn't go to the beach without putting sunblock on your body," said Dr.

    BalasHapus
  27. Did Yeezy jump over the Jumpman? In terms of hype and consumer draw, 2015 was the year of Kanye West and there’s no question that his new line of footwear called the Yeezy Boost did huge numbers for adidas. Every single release thus far – from the Jordan 5 fire red original Yeezy Boost 750 to the upcoming “Blackout” and Yeezy Boost 350 “Oxford Tan” – will be met with incredibly high demand on both retail and aftermarket, so it’s jordan releases clear that the three-stripes did well for themselves when it decided to pull ‘Ye away from the Swoosh. But for these huge companies, what it comes down to is jordan shoes cold hard cash and future outlook, and for one month counting from Black Friday, Jordan Brand will have sold more Retros than adidas will sell Yeezy Boosts all year jordan 11 long. We won’t go into the actual figures, but the Aqua 8s, 72-10 AJ11s, Maroon 6s, Public School x Air Jordan 12s, and the upcoming Chrome 8s are way jordans 2015 over 1,000,000 pairs in production (and we’re not even counting the Air Jordan 1.5, GS releases, and so on). In comparison, the amount of every Yeezy Boost since its Air Jordan 4 Alternate 89 debut doesn’t match that number.
    One of Nike’s most innovative and creative minds ever championed the “laser” movement of the early-mid 2000s, producing a wide variety of incredible releases new jordan shoes and samples featuring laser-cut graphics. Since then, Nike and Jordan Brand has leaned heavily on that method as a means to create something elevated and premium, but this latest new jordans creation is on such an exclusive tier that only one other man may own a pair. Chi McBride, a celebrated actor and legendary sneaker OG, was the recipient of jordans 2016 a lasered Air Jordan 7 that, according to his wife, is a 1-of-1 gift from Smith, a close friend. We’re only getting a preview of the toe-box of these Jordan Retro 8 Concord amazing friends-and-family only joints, so hopefully Mark, Chi, cheap jordans or his wife will reveal some more details. Get a look below at the shoes and the box.

    BalasHapus