C#为连接sql server数据库,写个DBHelper类

Roc posted @ 2010年6月25日 08:01 in C# , 8194 阅读

 

在DBHelper类中

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
namespace MySchool                                                                     //MySchool是我的项目名称
{
    class DBHelper
    {
        static string conString = "Data Source=服务器名;Initial Catalog=数据库名;User ID=sa";                                        //我选择的是windows+sql混合验证,登录名sa,如果有Pwd还需要添加
        public static SqlConnection con=new SqlConnection(conString);                                                                                //创建SqlConnection对象,用于连接
    }
}

 

然后在另一个类中(比如窗体类)可以调用
using System.Data.SqlClient;
string sql = "select * from teacher";                                                                       //输入的sql命令
SqlCommand cmd = new SqlCommand(sql,DBHelper.con);                        //创建SqlCommand对象,导入sql命令,连接的是DBHelper中写好的数据库
DBHelper.con.Open();                                                                                             //打开数据库
SqlDataReader dr = cmd.ExecuteReader();                                                       //创建SqlDataReader类对象,用于一行一行读取数据库中数据
dr.HasRows                                                                        //在数据库中执行select * from teacher,会有多行受到影响。如果有影响,HasRows返回true,否则返回false
dr.Read();                                                                                //读取一行数据,若想一遍一遍的读,一直到读完为止,则可以写到while语句中
string loginid = dr["LoginID"].ToString();                            //把数据库中字段LoginID的第一个记录给字符串loginid
Avatar_small
professional cleanin 说:
2021年9月29日 17:57

Spouse and children cleaning is just not an advantageous undertaking, as well as because the software involves excruciating activities, that include hard scrubbing up, but also while it may entail the installation of products which has been harmful to skin and also the body more often than not. A Norwegian understand, which recognized around 5000 wives mostly going through household chores with nasty chemicals, reported superior occurrences about chronic obstructive pulmonary problem (COPD) and additionally skin irritations in all of these subjects.

Avatar_small
NCERT 8th Class Solu 说:
2022年9月09日 03:50

Those Secondary Education Class VIII Standard students can download subject wise solutions in chapter wide for all subjects of the course introduced by the school education department for Hindi medium, English medium, NCERT 8th Class Solutions Urdu medium students designed and suggested by the National Council of Educational Research and Training (NCERT).The NCERT has introduced those Secondary education STD-8 subject wide answer solutions for Term-1, Term-2, Term-3, Term-4 in session wide for Session-1 & Session-2 (Part-A and Part-B) exams and published at their official web portals of NCERT & ePathshala, and various private websites also shared to the class 8th standard students studying at all regions of the country.

Avatar_small
seo service london 说:
2023年11月01日 19:08

Instantly this web site will irrefutably frequently end up being notable regarding all weblog consumers, due to diligent reviews as well as checks

Avatar_small
먹튀폴리스 说:
2023年11月02日 13:53

I really appreciate for your efforts you to put in this article, this is very informative and helpful. I really enjoyed reading this blog.So grab a drink, roll the dice, and let’s get began! With an LLC, you will have to file paperwork with the Secretary of State (or different company) to type the organization.

Avatar_small
SM카지노 최신주소 说:
2023年11月02日 14:46

Greetings, I do calculate your blog may really be having web program likeness issues. Whenever I research your blog in Safari, it looks fine anyway when opening in Internet Explorer, it makes them cover issues. I basically expected to give you a fast watch out! Other than that, great blog! This was really an entrancing point and I fairly agree with what you have referred to here

Avatar_small
토크리 说:
2023年11月02日 14:54

Thanks for sharing this interesting article, I really appreciate it.You may be focused on unusual cracks and break in your walls, your home has a problem with the foundation. Do not worry about it we can create a solid foundation for your property by giving the highest quality sub-floor work. Our company is specialized in underpinning, restumping, and subfloor repairs.

Avatar_small
스포츠토토사이트 说:
2023年11月02日 15:05

Are you looking for best North Carolina home builders?Your wait is over here. Just visit North Carolina Home Builders of the firm called GetNewHomeRebate provides the best construction for your private homes, flats, building tenements and much more. Make your construction safe and make your future bright by investing in real North Carolina home builders.

Avatar_small
토크리 说:
2023年11月02日 15:11

Thanks for sharing this interesting article, I really appreciate it.You may be focused on unusual cracks and break in your walls, your home has a problem with the foundation. Do not worry about it we can create a solid foundation for your property by giving the highest quality sub-floor work. Our company is specialized in underpinning, restumping, and subfloor repairs.

Avatar_small
슈어맨같은곳 说:
2023年11月02日 15:38

You truly make it look so normal with your presentation anyway I find this have an effect to be truly something which I figure I would never comprehend. It has all the earmarks of being unreasonably obfuscated and unbelievably wide for me. I'm looking forward for your next post, I'll endeavor to get its hang! This is such an extraordinary resource that you are giving and you part with it to no end. I love seeing site that fathom the value. Im glad to have found this post as it's anything but's a fascinating one! I'm by and large looking out for quality posts and articles so I accept im lucky to have found this! I believe you will add all the more later on. 

Avatar_small
토토사이트추천 说:
2023年11月02日 15:43

Surrounded by worries and stress? Your relief mantra is here! Crazy For Study brings optimum solutions to ease your academic burden. It’s cost effective, accredited and recommended by best brains worldwide! Bring wealth of knowledge at your home today, and get promising results!

Avatar_small
안전놀이터가입 说:
2023年11月02日 16:16

Excellent read, I just passed this onto a friend who was doing a little research on that. And he actually bought me lunch as I found it for him smile Therefore let me rephrase that: Thank you for lunch

Avatar_small
먹튀검증사이트 说:
2023年11月02日 16:42

Nice post. I was checking continuously this blog and I am impressed! Extremely useful info particularly the last part :) I care for such information much. I was seeking this particular info for a long time. Thank you and good luck. This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the good work.

Avatar_small
토토사이트 说:
2023年11月02日 16:47

Greetings, I do calculate your blog may really be having web program likeness issues. Whenever I research your blog in Safari, it looks fine anyway when opening in Internet Explorer, it makes them cover issues. I basically expected to give you a fast watch out! Other than that, great blog! This was really an entrancing point and I fairly agree with what you have referred to here

Avatar_small
안전놀이터 说:
2023年11月02日 16:52

it is extremely important and large to pick out to your goods from an extensive sort of holograms reachable in the market these days. Hologram stickers are one of the exceptional strategies, and it is going to be a useful technique to your business. I should search web sites with applicable facts on given subject matter and provide them to instructor our opinion and the object.

Avatar_small
토스타 说:
2023年11月02日 17:58

I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. So grab a drink, roll the dice, and let’s get began! With an LLC, you will have to file paperwork with the Secretary of State (or different company) to type the organization.Thank you so much

Avatar_small
승인전화없는 토토꽁머니 说:
2023年11月02日 18:10

Brilliant post! Your incorporation of practical tips and real-life examples adds substantial weight to your ideas. Your evident commitment is admirable. Anxiously awaiting your forthcoming content. Keep up the impressive work!

Avatar_small
토토사이트 说:
2023年11月02日 18:11

You truly make it look so normal with your presentation anyway I find this have an effect to be truly something which I figure I would never comprehend. It has all the earmarks of being unreasonably obfuscated and unbelievably wide for me. I'm looking forward for your next post, I'll endeavor to get its hang! This is such an extraordinary resource that you are giving and you part with it to no end. I love seeing site that fathom the value. Im glad to have found this post as it's anything but's a fascinating one! I'm by and large looking out for quality posts and articles so I accept im lucky to have found this! I believe you will add all the more later on. 

Avatar_small
무료가족방 说:
2023年11月02日 18:17

I am really impressed with your writing skills well with the layout for your weblog. Is that this a paid subject matter or did you modify it your self? Anyway stay up the nice high quality writing, it is rare to see a nice weblog like this one these days

Avatar_small
토토사이트검증 说:
2023年11月02日 18:23

I really appreciate for your efforts you to put in this article, this is very informative and helpful. I really enjoyed reading this blog.So grab a drink, roll the dice, and let’s get began! With an LLC, you will have to file paperwork with the Secretary of State (or different company) to type the organization.

Avatar_small
안전놀이터 说:
2023年11月02日 18:25

Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please

Avatar_small
카지노사이트 说:
2023年11月02日 18:39

Greetings, I do calculate your blog may really be having web program likeness issues. Whenever I research your blog in Safari, it looks fine anyway when opening in Internet Explorer, it makes them cover issues. I basically expected to give you a fast watch out! Other than that, great blog! This was really an entrancing point and I fairly agree with what you have referred to here

Avatar_small
토토사이트블랙조회 说:
2023年11月02日 18:51

ey there, i do suppose your weblog should in all likelihood be having internet browser compatibility problems. On every occasion i check your weblog in safari, it appears best bu

Avatar_small
토토사이트추천 说:
2023年11月02日 19:00

Thanks for sharing this interesting article, I really appreciate it.You may be focused on unusual cracks and break in your walls, your home has a problem with the foundation. Do not worry about it we can create a solid foundation for your property by giving the highest quality sub-floor work. Our company is specialized in underpinning, restumping, and subfloor repairs.

Avatar_small
카지노쿠폰 说:
2023年11月02日 19:12

Nice post. I learn something totally new and challenging on sites I stumbleupon every day. It will always be useful to read through articles

Avatar_small
토토코드거래소 说:
2023年11月02日 19:17

You truly make it look so normal with your presentation anyway I find this have an effect to be truly something which I figure I would never comprehend. It has all the earmarks of being unreasonably obfuscated and unbelievably wide for me. I'm looking forward for your next post, I'll endeavor to get its hang! This is such an extraordinary resource that you are giving and you part with it to no end. I love seeing site that fathom the value. Im glad to have found this post as it's anything but's a fascinating one! I'm by and large looking out for quality posts and articles so I accept im lucky to have found this! I believe you will add all the more later on. 

Avatar_small
텍사스홀덤특징 说:
2023年11月02日 19:27

I am very impressed with your post because this post is very beneficial for me and provide a new knowledge to me Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family

Avatar_small
먹튀검증 说:
2023年11月02日 19:30

Surrounded by worries and stress? Your relief mantra is here! Crazy For Study brings optimum solutions to ease your academic burden. It’s cost effective, accredited and recommended by best brains worldwide! Bring wealth of knowledge at your home today, and get promising results!

Avatar_small
토토사이트배너 说:
2023年11月02日 19:36

Worldwide best and fastest 3d Rendering outsource providers, Services may like Australia, Canada, United states, United kingdom, Newzealand and China countries, We 3D Rendering China provides many services for a purpose like 3d Industrial modeling,3d Architectural Rendering, 3d Medical Illustration

Avatar_small
แนะนำ เว็บไซต์บาคาร่ 说:
2023年11月02日 19:59

You truly make it look so normal with your presentation anyway I find this have an effect to be truly something which I figure I would never comprehend. It has all the earmarks of being unreasonably obfuscated and unbelievably wide for me. I'm looking forward for your next post, I'll endeavor to get its hang! This is such an extraordinary resource that you are giving and you part with it to no end. I love seeing site that fathom the value.

Avatar_small
토토사이트 说:
2023年11月02日 20:03

Excellent read, I just passed this onto a friend who was doing a little research on that. And he actually bought me lunch as I found it for him smile Therefore let me rephrase that: Thank you for lunch

Avatar_small
먹튀사이트 说:
2023年11月02日 20:17

it is extremely important and large to pick out to your goods from an extensive sort of holograms reachable in the market these days. Hologram stickers are one of the exceptional strategies, and it is going to be a useful technique to your business. I should search web sites with applicable facts on given subject matter and provide them to instructor our opinion and the object.

Avatar_small
먹튀사이트 说:
2023年11月02日 20:27

Surrounded by worries and stress? Your relief mantra is here! Crazy For Study brings optimum solutions to ease your academic burden. It’s cost effective, accredited and recommended by best brains worldwide! Bring wealth of knowledge at your home today, and get promising results!

Avatar_small
토토사이트 说:
2023年11月02日 20:40

Greetings, I do calculate your blog may really be having web program likeness issues. Whenever I research your blog in Safari, it looks fine anyway when opening in Internet Explorer, it makes them cover issues. I basically expected to give you a fast watch out! Other than that, great blog! This was really an entrancing point and I fairly agree with what you have referred to here

Avatar_small
먹튀검증 说:
2023年11月02日 20:41

Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.So grab a drink,

Avatar_small
토토커뮤니티추천 说:
2023年11月02日 20:42

You really make it seem really easy along with your presentation however I to find this topic to be actually one thing which I believe I might never understand.I would like to suggest you that please keep sharing such type of info.Thanks 

Avatar_small
파라오카지노 说:
2023年11月02日 20:53

Your article is what I've been looking for for a long time. I'm happy to find you like this. Could you visit my website if you have time? I'm sure you'll find a post of interest that you'll find interesting.

Avatar_small
사설토토추천 说:
2023年11月02日 21:04

Nice post. I was checking continuously this blog and I am impressed! Extremely useful info particularly the last part :) I care for such information much. I was seeking this particular info for a long time. Thank you and good luck. This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the good work.

Avatar_small
먹튀사이트 说:
2023年11月02日 21:04

Thank you for sharing your info. I really appreciate your efforts and Thanks a lot for sharing a piece of wonderful information which I am looking for a longer period of timeSo grab a drink, roll the dice, and let’s get began! With an LLC, you will have to file paperwork with the Secretary of State (or different company) to type the organization.

Avatar_small
사설토토추천 说:
2023年11月02日 21:05

Nice post. I was checking continuously this blog and I am impressed! Extremely useful info particularly the last part :) I care for such information much. I was seeking this particular info for a long time. Thank you and good luck. This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the good work.

Avatar_small
토토검증 说:
2023年11月02日 21:16

Worldwide best and fastest 3d Rendering outsource providers, Services may like Australia, Canada, United states, United kingdom, Newze

Avatar_small
메이저놀이터 说:
2023年11月02日 21:16

Really decent post. I just discovered your weblog and needed to say that I have truly delighted in searching your blog entries. After all I'll be subscribing to your food and I trust you compose again soon! This article was written by a real thinking writer. I agree many of the with the solid points made by the writer. I’ll be back.

Avatar_small
먹튀사이트 说:
2024年1月15日 15:12

I really enjoy simply reading all of your weblogs. Simply wanted to inform you that you have people like me who appreciate your work. Definitely a great post. Hats off to you! The information that you have provided is very helpful.

Avatar_small
슬롯커뮤니티 说:
2024年1月15日 17:21

I really like your take on the issue. I now have a clear idea on what this matter is all about

Avatar_small
토토사이트 说:
2024年1月15日 18:21

You have a good point here!I totally agree with what you have said!!Thanks for sharing your views...hope more people will read this article!!

Avatar_small
소액결제현금화 说:
2024年1月15日 18:40

"`I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you!
Excellent read, Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work.

"

Avatar_small
카지노사이트 说:
2024年1月15日 19:04

I went over this website and I believe you have a lot of wonderful information, saved to my bookmarks

Avatar_small
스포츠무료중계 说:
2024年1月15日 19:18

I need to to thank you for this very good read!! I definitely loved every little bit of it. I have you bookmarked to check out new things you post

Avatar_small
카지노사이트 说:
2024年1月15日 20:03

Wow, cool post. I'd like to write like this too — taking time and real hard work to make a great article… but I put things off too much and never seem to get started. Thanks though.

Avatar_small
ios industrial real 说:
2024年1月15日 20:05

"`I like viewing web sites which comprehend the price of delivering the excellent useful resource free of charge. I truly adored reading your posting. Thank you!
Excellent read, Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work.

"

Avatar_small
토토사이트 说:
2024年1月15日 20:43

Your blog provided us with valuable information to work with. Each & every tips of your post are awesome. Thanks a lot for sharing. Keep blogging,

Avatar_small
슬롯사이트 说:
2024年1月16日 13:27

useful information on topics that plenty are interested on for this wonderful post.Admiring the time and effort you put into your b!..

Avatar_small
바카라사이트 说:
2024年1月16日 13:58

It is a completely interesting blog publish.I often visit your posts for my project's help about Diwali Bumper Lottery and your super writing capabilities genuinely go away me taken aback.Thank you a lot for this publish.

Avatar_small
바카라 커뮤니티 说:
2024年1月16日 16:45

You have a good point here! I totally agree with what you have said !! Thanks for sharing your views. hope more people will read this article !!

Avatar_small
카지노 커뮤니티 说:
2024年1月16日 17:36

"I for all time emailed this websie post page tto all my friends, as if like to resad it aftedr
that my friends will too."

Avatar_small
카지노사이트 说:
2024年1月18日 13:49

i am for the first time here. I found this board and I in finding It truly helpful & it helped me out a lot. I hope to present something back and help others such as you helped me.

Avatar_small
메이저사이트 说:
2024年1月18日 16:13

I personally use them exclusively high-quality elements : you will notice these folks during

Avatar_small
바카라 사이트 추천 说:
2024年1月22日 11:40

온라인 카지노 커뮤니티 온카허브 입니다. 온카허브는 카지노 먹튀 사이트들과 안전한 카지노 사이트 정보를 공유하고 있습니다. 카지노 먹튀검증 전문팀을 자체적으로 운영함으로써 철저한 검증을 진행하고 있습니다. <a href="https://oncahub24.com/">바카라 사이트 추천</a>

Avatar_small
온라인 카지노 먹튀 说:
2024年1月22日 12:18

온라인 카지노 커뮤니티 온카허브 입니다. 온카허브는 카지노 먹튀 사이트들과 안전한 카지노 사이트 정보를 공유하고 있습니다. 카지노 먹튀검증 전문팀을 자체적으로 운영함으로써 철저한 검증을 진행하고 있습니다.

Avatar_small
무료스포츠중계 说:
2024年1月22日 15:12

Very interesting, good job and thanks for sharing such a good blog. your article is so convincing that I never stop myself to say something about it. You’re doing a great job. Keep it up

Avatar_small
먹튀검증 说:
2024年1月22日 15:38

i read a lot of stuff and i found that the way of writing to clearifing that exactly want to say was very good so i am impressed and ilike to come again in future..

Avatar_small
카지노 说:
2024年1月23日 17:39

카지노 우리카지노 카지노는 바카라, 블랙잭, 룰렛 및 슬롯 등 다양한 게임을 즐기실 수 있는 공간입니다. 게임에서 승리하면 큰 환호와 함께 많은 당첨금을 받을 수 있고, 패배하면 아쉬움과 실망을 느끼게 됩니다.

Avatar_small
바카라 사이트 추천 说:
2024年1月23日 17:44

하노이 꼭 가봐야 할 베스트 업소 추천 안내 및 예약, 하노이 밤문화 에 대해서 정리해 드립니다. 하노이 가라오케, 하노이 마사지, 하노이 풍선바, 하노이 밤문화를 제대로 즐기시기 바랍니다. 하노이 밤문화 베스트 업소 요약 베스트 업소 추천 및 정리.

Avatar_small
먹튀사이트 说:
2024年1月25日 11:24

No.1 먹튀검증 사이트, 먹튀사이트, 검증사이트, 토토사이트, 안전사이트, 메이저사이트, 안전놀이터 정보를 제공하고 있습니다. 먹튀해방으로 여러분들의 자산을 지켜 드리겠습니다. 먹튀검증 전문 커뮤니티 먹튀클린만 믿으세요!!

Avatar_small
베트남 밤문화 说:
2024年1月25日 14:59

베트남 남성전용 커뮤니티❣️ 베트남 하이에나 에서 베트남 밤문화를 추천하여 드립니다. 베트남 가라오케, 베트남 VIP마사지, 베트남 이발관, 베트남 황제투어 남자라면 꼭 한번은 경험 해 봐야할 화끈한 밤문화로 모시겠습니다. 


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter